Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firefox 根据selenium IDE 2.9.1,无法单击xpath显示正确的按钮_Firefox_Xpath_Selenium Webdriver - Fatal编程技术网

Firefox 根据selenium IDE 2.9.1,无法单击xpath显示正确的按钮

Firefox 根据selenium IDE 2.9.1,无法单击xpath显示正确的按钮,firefox,xpath,selenium-webdriver,Firefox,Xpath,Selenium Webdriver,我需要为“New”按钮编写xpath 已尝试:- By.xpath("//form[@action='/intruvert/action/CustomRolesAction']/div/div[3]/div/a[1]") By.xpath("//form[@name='CustomRolesForm']/div/div[3]/div/a[@style='background-color: rgb(242, 242, 242);' and @title='New']") By.xpath("/

我需要为“New”按钮编写xpath

已尝试:-

By.xpath("//form[@action='/intruvert/action/CustomRolesAction']/div/div[3]/div/a[1]")

By.xpath("//form[@name='CustomRolesForm']/div/div[3]/div/a[@style='background-color: rgb(242, 242, 242);' and @title='New']")

By.xpath("//form[@name='CustomRolesForm']/div/div[3]/div/a[@title='New']")
但无法单击“新建”按钮

我不确定我是否遗漏了什么

请建议

代码如下:-


您可以尝试直接定位按钮,而无需使用祖先

// by class name
By.className("genericbtn")
// by title
By.cssSelector("[title='New']")
// by partial href
By.cssSelector("[href*='add']")

您可以尝试直接定位按钮,而无需使用祖先

// by class name
By.className("genericbtn")
// by title
By.cssSelector("[title='New']")
// by partial href
By.cssSelector("[href*='add']")
只需使用文本查找
a
标记即可

表示当前上下文节点(
a

只需使用文本查找
a
标记即可


表示当前上下文节点(
a
)。

您可以使用titletext属性查找所需链接:

By.xpath("//a[@title='New']");


您可以使用titletext属性查找所需链接:

By.xpath("//a[@title='New']");


@在查看您的代码后,我发现javascript错误。在html中,您没有在任何地方定义javascript。看到图片了吗

你的html

<a class="genericbtn" title="New" href="javascript:doSubmit('add')">New</a>


@在查看您的代码后,我发现javascript错误。在html中,您没有在任何地方定义javascript。看到图片了吗

你的html

<a class="genericbtn" title="New" href="javascript:doSubmit('add')">New</a>

<a class="genericbtn" title="New" href="#">New</a>
WebElement new_button = driver.findElement(By.xpath("//a[contains(text(), 'New')]"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", new_button);
driver.findElement(By.xpath("//a[contains(text(), 'New')]")).click();