2016-09-22 17 views
0

enter image description here定时输出10秒来等待位于元素的存在之后使用Selenium Wedriver

定位器这是正确的,但在硒的webdriver运行它时,我收到了同样的错误。 我用不同种类的像隐观望,等待明确的等待,并等待在场元素

WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.xp‌​ath("//div[@id = 'bs-example-navbar-collapse-1']/ul[2]/li[1]"))); 
driver.findElement(By.xpath("//div[@id = 'bs-example-navbar-collapse-1']/ul[2]/li[1]")).click(); 
+1

分享您硒和html代码 –

+0

WebElement myDynamicElement =(new WebDriverWait(driver,10))。until(ExpectedConditions.presenceOfElementLocated(By.xpath(“// div [@id ='bs-example-navbar-collapse-1']/ul [2 ] /锂[1]“))); driver.findElement(By.xpath(“// div [@id ='bs-example-navbar-collapse-1']/ul [2]/li [1]”))。click(); –

+0

你能分享这个网站吗? –

回答

0

而不是使用“presenceOfElementLocated(通过定位器)”,使用“visibilityOfElementLocated(通过定位器)”的。 'presenceOfElementLocated(By locator)'只能确认DOM中是否存在元素,但并不表示该元素是可见或启用的。但是,如果您使用'visibilityOfElementLocated(By locator)',那么它确认该元素存在于DOM中并且可见。如果你点击元素,你也可以使用'elementToBeClickable(By locator)';

0

其Shine.com,点击登录链接在右上方

你应该尝试使用By.linkText()点击如下Login按钮: -

driver.get("http://www.shine.com/"); 

WebDriverWait wait = new WebDriverWait(driver, 10);  
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Login"))).click(); 
+0

我更喜欢使用By.className(“logedin”),因为链接文本可以在页面呈现其他语言时更改。 – vbail

相关问题