Java 选择按钮的Xpath
下面的检查代码是点击按钮,我可以确认我的订单Java 选择按钮的Xpath,java,selenium,xpath,css-selectors,webdriverwait,Java,Selenium,Xpath,Css Selectors,Webdriverwait,下面的检查代码是点击按钮,我可以确认我的订单 <button type="submit" class="button btn btn-default button-medium"> <span>I confirm my order<i class="icon-chevron-right right"></i></span> </button
<button type="submit" class="button btn btn-default button-medium">
<span>I confirm my order<i class="icon-chevron-right right"></i></span>
</button>
<span>I confirm my order<i class="icon-chevron-right right"></i></span>
使用Eclipse作为硒测试的IDE时出现以下错误:
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //button[contains(text(),'I confirm my order')]" because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//button[contains(text(),'I confirm my order')]"' is not a valid XPath expression.
试试这个:
driver.find_element_by_xpath('//button[@type="submit"]/span[1]').click()
文本I confirm my order位于
元素的子
中。因此,要单击元素上的()
,可以使用以下任一选项:
:css选择器
driver.findElement(By.cssSelector("button.button.btn.btn-default.button-medium > span i.icon-chevron-right.right")).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.button.btn.btn-default.button-medium > span i.icon-chevron-right.right"))).click();
:xpath
driver.findElement(By.xpath("//button[@class='button btn btn-default button-medium'][./span[contains(., 'I confirm my order')]]")).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='button btn btn-default button-medium'][./span[contains(., 'I confirm my order')]]"))).click();
在需要归纳的元素上单击()
,以使elementtobelickable()
,您可以使用以下任一选项:
:css选择器
driver.findElement(By.cssSelector("button.button.btn.btn-default.button-medium > span i.icon-chevron-right.right")).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.button.btn.btn-default.button-medium > span i.icon-chevron-right.right"))).click();
:xpath
driver.findElement(By.xpath("//button[@class='button btn btn-default button-medium'][./span[contains(., 'I confirm my order')]]")).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='button btn btn-default button-medium'][./span[contains(., 'I confirm my order')]]"))).click();