【问题标题】:unable to perforn next action after performing one action in selenium webdriver . I was doing testing on trivago.com and below is my code在 selenium webdriver 中执行一个操作后无法执行下一个操作。我在 trivago.com 上进行测试,下面是我的代码
【发布时间】:2017-08-03 03:13:48
【问题描述】:
driver.findElement(By.xpath(".//*[@id='js-fullscreen-hero']/div/form/div[1]/div/div/div[2]/button")).click();
new WebDriverWait(driver, 10 ).ignoring(StaleElementReferenceException.class).until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[@id='horus-shadowtext']")));
WebElement  ele = driver.findElement(By.xpath(".//*[@id='horus-shadowtext' and @class='horus__shadowtext']"));
List<String> windowlist = new ArrayList<String>();
windowlist.add(driver.getWindowHandle());
int si=  windowlist.size();
System.out.println(si);
Actions mouse2 = new Actions(driver);
mouse2.clickAndHold(ele).sendKeys(Keys.chord(Keys.CONTROL,"china")).build().perform();
ele.sendKeys(Keys.ENTER);

在此之后,即使是下面的步骤,它也无法执行任何步骤

driver.findElement(By.xpath(".//*[@id='js-fullscreen-hero']/div/form/div[1]/div[1]/div/div[2]/button")).click();

谁能帮我找出正确的解决方案。

【问题讨论】:

  • 您能否总结一下您尝试自动化的确切手动步骤?您在哪一行看到错误?请更新问题区域中的错误堆栈跟踪以及相关的 HTML。谢谢
  • 用文字描述您要测试的用例。同时提供minimal reproducible example。理想情况下,这应该是 selenium 测试代码以及​​您尝试测试的代码的非常淡化的版本。
  • 下面是错误日志
  • 线程“主”org.openqa.selenium.NoSuchElementException 中的异常:无法定位元素:.//*[@id='js-fullscreen-hero']/div/form/div[ 3]/div[2]/button 有关此错误的文档,请访问:seleniumhq.org/exceptions/no_such_element.html Build info: version: 'unknown', revision: 'unknown', time: 'unknown' System info: host: 'PEAMITRA', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121' 驱动信息: org.openqa.selenium.firefox.FirefoxDriver
  • 当我没有使用控件时它能够定位元素。

标签: java selenium


【解决方案1】:

试试这个

WebElementsource = driver.findElement(BylocatorType("path"));

或者

通过以下链接使用一些有效的选择 XPath 的技术:

http://toolsqa.com/selenium-webdriver/choosing-effective-xpath/

为了进一步探索,我会推荐另一个链接

WebDriver can't find element by xpath using Java

希望它能解决您的问题。

谢谢!

【讨论】:

  • 以上方法我已经试过了。但它无法执行任何操作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-15
  • 2018-03-14
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
  • 2021-11-23
相关资源
最近更新 更多