我爱编程

selenium定位不可见元素

2017-07-06  本文已影响0人  红木杉2018

package seleniumdemo;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.JavascriptExecutor;

import org.openqa.selenium.firefox.FirefoxDriver;

public class TestDay01 {

public static void main(String[] args) {

// TODO Auto-generated method stub

FirefoxDriver driver=new FirefoxDriver();

driver.get("https://www.hczhifu.com/");

driver.findElement(By.cssSelector("div.double_Btn>a:nth-child(1)")).click();

driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);

driver.findElement(By.cssSelector("#userName")).sendKeys("1234567");

//修改不可见元素为可见

String js = "document.getElementById('password').style.display='block';";

((JavascriptExecutor)driver).executeScript(js);

driver.findElement(By.cssSelector("#password")).sendKeys("123456");

}

}

上一篇 下一篇

猜你喜欢

热点阅读