有没有办法测试元素是否存在?任何findElement方法都会以异常结束,但这不是我想要的,因为它可能是一个元素不存在而且没关系,这不是测试的失败,因此异常不能成为解决方案.
我发现这篇文章:Selenium c#Webdriver:等到元素存在 但是这是C#而我不是很擅长.任何人都可以将代码翻译成Java吗?我很抱歉,我在Eclipse中尝试过但是我没有把它直接用到Java代码中.
这是代码:
public static class WebDriverExtensions{
public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds){
if (timeoutInSeconds > 0){
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
return wait.Until(drv => drv.FindElement(by));
}
return driver.FindElement(by);
}
}
Run Code Online (Sandbox Code Playgroud) 当我尝试使用class = "country name"在页面对象中有空格的类名时,我得到:
Compound class names not permitted Selenium::WebDriver::Error::UnknownError)
Run Code Online (Sandbox Code Playgroud)
如何使用具有空格的类名.
例如:
class = "country name"
Run Code Online (Sandbox Code Playgroud)