Selenium兼容性问题注意

不知道是selenium兼容做的不好,还是浏览器自身运行速度和解析的关系,每次项目在chrome上跑得时候没有问题,可以到chrome和safari上就有很多问题出现。下面一一总结出现的问题以及解决方案。

1、当页面跳转后,防止jquery ajax等事件未加载出需要操作的元素时,可以使用下面代码控制元素出现后再执行操作。

public static void waitForPage(WebDriverWait wait, By by) {wait.until(ExpectedConditions.presenceOfElementLocated(by));}

2、当页面在chrome上跳转时,验证跳转的url是否和excepted的url一致时,,会出现运行过快url判断还停留在上一个url的问题。

/*** set i=50 (one is 100 millseconds) represent 5 seconds* @param url expected url*/public static void pageload(String url){WebDriver driver = new IndexPage().getDriver();int i=0;while(i < 50) {i++;if(driver.getCurrentUrl().equals(url)) {break;} else {try {Thread.sleep(100);} catch (InterruptedException e) {e.printStackTrace();}}}}

3、当在chrome上运行弹框时,会出现如下错误:NoSuchAlertError: no alert open,解决方案可能有的人在Alert之前sleep一秒,但是我觉得这样做是不正确的,正确的做法如下:

public static void waitForAlert(WebDriverWait wait) {wait.until(ExpectedConditions.alertIsPresent());}

版权声明:本文为博主原创文章,未经博主允许不得转载。

有事者,事竟成;破釜沉舟,百二秦关终归楚;苦心人,

Selenium兼容性问题注意

相关文章:

你感兴趣的文章:

标签云: