繁体   English   中英

无法使用Xpath和CSS查找元素

[英]Unable to find element using Xpath and CSS

我无法使用XPATH和CSS找到Element

我正在使用firefox执行代码,我尝试了每种方法来查找此处提到的元素,但总是收到以下提到的错误。

1500539792269 geckodriver INFO geckodriver 0.18.0 1500539792279 geckodriver INFO侦听127.0.0.1:18947 1500539793062 geckodriver :: marionette INFO启动浏览器C:\\ Program Files(x86)\\ Mozilla Firefox \\ firefox.exe,带有args [“ -marionette”] 1500539798479 Marionette INFO在端口64608上侦听2017年7月20日下午2:06:39 org.openqa.selenium.remote.ProtocolHandshake createSession INFO:检测到方言:W3C JavaScript警告: https ://login-qa.ihg.com/forms/iam/ sensitiveV3 / js / jquery.min.js ,第1行:使用// @表示不建议使用sourceMappingURL编译指示。 在线程“ main”中使用//#代替Exception org.openqa.selenium.NoSuchElementException:无法找到元素:侧栏按钮有关此错误的文档,请访问: http : //seleniumhq.org/exceptions/no_such_element.html Build信息:版本:“未知”,修订版:“未知”,时间:“未知”

码:

driver.findElement(By.id("sidebar-button")).click();
Thread.sleep(2000);
Actions action = new Actions(driver);
WebElement we = driver.findElement(By.xpath("//*[@id='reservations']/a"));
action.moveToElement(we).build().perform();

请帮我解决这个问题

driver.findElement(By.id("sidebar-button")).click();之前等待一些时间driver.findElement(By.id("sidebar-button")).click();

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(
    ExpectedConditions.visibilityOfElementLocated(By.id("sidebar-button")));  

当您在第一行得到'NoSuchElementException'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM