编程语言
首页 > 编程语言> > java版selnium_demo

java版selnium_demo

作者:互联网

1.环境:jdk

2.实例代码:

        ChromeOptions OPTIONS =new ChromeOptions();
		OPTIONS.addArguments("--no-sandbox");
		WebDriver driver = new  ChromeDriver(OPTIONS);
		driver.get("https://www.kdocs.cn/view/l/sa1XFpAYtsZn");
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		driver.switchTo().frame(driver.findElement(By.id("my-ckt-iframe")));
		driver.findElement(By.id("icon-download")).click();

      注意事项:
        1.获取元素时,要确认其是否在iframe中若在iframe中需先进入iframe,否则会报元素找不到

        2.进行点击事件时,要确认元素是否绑定有事件,否则会报元素无法交互的错误(element not interactable)

        3.相应jar包下载地址如下(本人使用版本:3.9.1):http://selenium-release.storage.googleapis.com/index.html?path=3.9/

        

标签:java,selnium,demo,元素,driver,id,iframe,OPTIONS,3.9
来源: https://blog.csdn.net/lwz18642660013/article/details/122343097