Firefox 根据selenium IDE 2.9.1,无法单击xpath显示正确的按钮
我需要为“New”按钮编写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("/
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
)。您可以使用title或text属性查找所需链接:
By.xpath("//a[@title='New']");
或
或
您可以使用title或text属性查找所需链接:
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();