可以为使用Selenium WebDriver的人提供帮助吗?
我一直在尝试在Mac机器上使用Selenium WebDriver自动化测试场景。当我将Safari定义为浏览器时"An element could not be located on the page using the given search parameters"
,即使该元素存在于Java代码Issues / Bug中的页面上,我也会出错。
注意:当我们选择Firefox和Chrome作为浏览器时,可以找到相同的元素。有一些类似的答案,但没有一个是关于Safari浏览器和Mac机器的。
尝试稍等。使用流利的等待方式如下:
WebElement waitsss(WebDriver driver, By elementIdentifier){
Wait<WebDriver> wait =
new FluentWait<WebDriver>(driver).withTimeout(60, TimeUnit.SECONDS)
.pollingEvery(1, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
return wait.until(new Function<WebDriver, WebElement>()
{
public WebElement apply(WebDriver driver) {
return driver.findElement(elementIdentifier);
}
});
}
等待应该为您工作。如果问题仍然存在,请使用JavascriptExecutor
。它将直接通过JS运行。它应该工作。我举一个例子来点击使用JavascriptExecutor
WebElement element = driver.findElement(By.id("gbqfd"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
希望它能对您有所帮助:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句