gpt4 book ai didi

selenium - 如何解决 org.openqa.selenium.WebDriverException?

转载 作者:行者123 更新时间:2023-12-01 09:57:53 27 4
gpt4 key购买 nike

我正在编写一个自动化测试,如果出现错误,我想直接在 GitHub 的存储库中报告。在我的程序中失败的步骤是来自 GitHub Issue Tracker 的 Submit new issue 按钮。

代码如下:

WebElement sendIssue = driver.findElement(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button"));

sendIssue.click();

异常(exception)情况:

org.openqa.selenium.WebDriverException: Element is not clickable atpoint (883, 547.7999877929688). Other element would receive the click:div class="modal-backdrop"></div

以下命令也不起作用:

((JavascriptExecutor) driver).executeScript("arguments[0].click();", sendIssue);

如何让它可以点击?有没有其他方法可以解决这个问题?

enter image description here

最佳答案

发生这种情况是因为当 selenium 试图点击时,所需的元素不可点击。

您必须确保您提供的 Xpath 绝对正确。如果您对 Xpath 有把握,请尝试以下操作

替换

WebElement sendIssue = driver.findElement(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button"));

sendIssue.click();

WebElement sendIssue =(WebElement)new WebDriverWait(DRIVER,10).until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button")));
sendIssue.click();

如果这不起作用,您将得到一个超时异常,在这种情况下尝试将超时量从 10 增加到 20。

如果仍然无法正常工作,请张贴 HTML 的屏幕截图。

您需要在问题标题和描述中写一些内容以使问题可点击,您确定您没有犯下点击按钮而不在那些地方写任何东西的错误我添加屏幕截图是为了您的方便。 If you dont enter the valid inputs the element is not clickable

关于selenium - 如何解决 org.openqa.selenium.WebDriverException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37205957/

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