下面的检查代码我已经是点击按钮,我可以确认我的订单
<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>
我试过的那个:
driver.findElement(By.xpath("//button[contains(text(),'I confirm my order')]\"")).click();
使用eclipse作为ide进行selenium测试时出现以下错误:
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.
2条答案
按热度按时间5anewei61#
试试这个:
m0rkklqb2#
文本我确认我的命令是在孩子
<span>
的<button>
元素。所以,为了click()
在元素上,可以使用以下任一定位器策略:cssSelector
: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.cssSelector("button.button.btn.btn-default.button-medium > span i.icon-chevron-right.right"))).click();
```
xpath
: