加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

Java编程语言下 Selenium 驱动各个浏览器代码

发布时间:2020-12-14 06:15:38 所属栏目:Java 来源:网络整理
导读:这里采用的是Selenium3.7版本, 总结下注意事项: 1,设置各个浏览器的Driver路径 System.setProperty("",""); 2,创建一个浏览器对象 WebDriver driver = new xxx(); ? 1. 驱动IE浏览器 IE浏览器的驱动有32位和64位,两个版本,建议使用32的IEdriver,因为6

这里采用的是Selenium3.7版本,

总结下注意事项:

1,设置各个浏览器的Driver路径

System.setProperty("","");

2,创建一个浏览器对象

WebDriver driver = new xxx();

?

1. 驱动IE浏览器

IE浏览器的驱动有32位和64位,两个版本,建议使用32的IEdriver,因为64位的IE driver 跑起来实在太慢了。

注意IE的保护模式,在各个状态下,全部禁用。如下截图,4个模式下,保护模式全部不勾选

<div class="cnblogs_code">

  
    
   
        main(String args[])  
         System.setProperty("webdriver.ie.driver",".ToolsIEDriverServer.exe"         WebDriver driver =           driver.get("http://www.baidu.com"         String s =          driver.manage().timeouts().implicitlyWait(10         Thread.sleep(1000  
  }

2. 驱动Chrome浏览器

main(String args[]) System.setProperty("webdriver.chrome.driver",".Toolschromedriver.exe" ChromeOptions options = DesiredCapabilities capabilities = capabilities.setCapability("chrome.switches",Arrays.asList("--start-maximized" options.addArguments("--test-type","--start-maximized" WebDriver driver = driver.get("http://www.baidu.com" driver.manage().timeouts().implicitlyWait(10 Thread.sleep(1000 }

3. 驱动火狐FireFox浏览器

main(String args[]) System.setProperty("webdriver.Firefox.driver",".Toolsgeckodriver.exe" WebDriver driver = driver.get("http://www.baidu.com" String s = driver.manage().timeouts().implicitlyWait(10 Thread.sleep(1000 }

?浏览器驱动的下载地址

常见的错误汇总

1. org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Browser zoom level was set to 75%. It should be set to 100% (WARNING: The server did not provide any stacktrace information)

ie浏览器显示百分比,需要调节到100%

2. org.openqa.selenium.ElementNotVisibleException: The point at which the driver is attempting to click on the element was not scrolled into the viewport. (WARNING: The server did not provide any stacktrace information)

不同设备,窗口大小问题,页面没有显示全,需要向下滚动

3.org.openqa.selenium.SessionNotCreatedException: session not created exception: Chrome version must be >= 66.0.3359.0

Chrome浏览器驱动版本不匹配的问题,需要查询目前chrome版本,下载匹配的驱动

4.No such Element Exception元素定位的方式有误,原因:页面源码改动原因: 元素还不是可用的状态原因: 出现弹窗

?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读