【问题标题】:Selenium WebDriver findElement(By.xpath()) not workingSelenium WebDriver findElement(By.xpath())不工作
【发布时间】:2014-11-06 07:44:08
【问题描述】:

我正在尝试使用 xpath 来单击元素。但它不起作用。

<a id="ProductListProductLink_414303" data-test="ProductListProductLink_3" href="http://uat-staging.wc7.dunelm.com/product/dorma-red-capri-collection-flat-sheet?searchTerm=sheet double">  

我尝试了多种方式。但没用。

有人可以帮帮我吗?

【问题讨论】:

  • 能否提供您一直用于点击元素的代码?

标签: xpath selenium-webdriver


【解决方案1】:

确保您使用 ('') 单引号传递 xpath id。当您从浏览器复制 xpath 时,它带有双引号。

以下示例将帮助您了解基本的 xpath 想法:

WebDriver driver = new FirefoxDriver();

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

driver.findElement(By.xpath("//*[@id='gbqfq']")).sendKeys("software testing");

【讨论】:

  • 他不必使用单引号。但是使用单引号更干净。他可以使用转义字符,例如“\”。而且,查看他的 html sn-p 可以假设该 Id 是随机生成的,因此您的 xpath 不会帮助他。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
  • 2023-03-22
相关资源
最近更新 更多