gpt4 book ai didi

java - Selenium 无法识别弹出窗口上的对象

转载 作者:行者123 更新时间:2023-11-30 02:48:14 24 4
gpt4 key购买 nike

popover on a iframe window

大家好,有人可以帮助我为什么我无法选择“从帐户中删除”按钮。如果您查看屏幕截图, Selenium 会成功单击显示弹出窗口的星号。然后我希望 Selenium 单击“从帐户中删除”按钮,但它不起作用。感谢任何帮助

这是我的代码:

public void clickSpecialPricingRemoveFromAccount(){
webDriver.findElement(By.xpath("//*[@id='singleProductTR']/td[6]/div/div[2]/div/div/div/div[2]/button[1])")).click();
}

我收到的错误消息是:

org.openqa.selenium.InvalidSelectorException: The given selector //[@id='singleProductTR']/td[6]/div/div[2]/div/div/div/div[2]/button[1]) is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: Unable to locate an element with the xpath expression //[@id='singleProductTR']/td[6]/div/div[2]/div/div/div/div[2]/button[1]) because of the following error: SyntaxError: The expression is not a legal expression. Command duration or timeout: 31 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46' System info: host: 'wdhl843a4bd282a8.corp.intuit.net', ip: '172.17.205.71', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_91' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=46.0.1, platform=MAC, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 6ef87e2b-beae-424c-9fdf-a3728e4995c4 *** Element info: {Using=xpath, value=//*[@id='singleProductTR']/td[6]/div/div[2]/div/div/div/div[2]/button[1])}

最佳答案

org.openqa.selenium.InvalidSelectorException: The given selector //[@id='singleProductTR']/td[6]/div/div[2]/div/div/div/div[2]/button[1]) is either invalid or does not result in a WebElement

您提供的 xpath 看起来语法不正确,应该是:-

//*[@id='singleProductTR']/td[6]/div/div[2]/div/div/div/div[2]/button[1]

您已在末尾附加了 ) 和此 xpath,但本不应该出现在此处。

但是您可以使用更具体的 xpath 来代替,使用 innerText 会更稳定,如下所示:-

webDriver.findElement(By.xpath(".//button[text() = 'Remove from Account']").click();

关于java - Selenium 无法识别弹出窗口上的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39516861/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com