【发布时间】:2019-04-16 13:15:24
【问题描述】:
无法使用 id/name/xpath/CSSSelector 定位元素
尝试了以下代码,但都没有给出响应
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\'form\']/p/button/span")));
driver.findElement(By.xpath("//*[@id=\'form\']/p/button/span")).click();
和
WebElement checkout = driver.findElement(By.xpath("//[@id=\'form\']/p/button/span"));
checkout.click();
HTML
<button type="submit" name="processCarrier" class="button btn btn-default standard-checkout button-medium" style="">
<span> Proceed to checkout <i class="icon-chevron-right right"></i> </span>
</button>
【问题讨论】:
-
HTML:
-
也许该元素在 iframe 内,而 webdriver 不在该 iframe 内。查找任何 iframe,如果元素在其中,则执行
driver.switchTo().frame("frame_id_or_index_goes_here") -
有什么答案可以解决您的问题吗?如果是,那么请通过单击答案投票计数下方的勾号来接受答案。所以它可以对其他人有所帮助。如果不是,请使用更多详细信息更新您的问题,或随时在 cmets 中提问。谢谢:)
标签: java selenium xpath css-selectors webdriverwait