我尝试了不同的xpath等,但无法在我的应用程序中单击“继续”按钮。以下是处理相同问题的尝试之一:-
WebDriverWait wait2 = new WebDriverWait(driver,20);
WebElement continueBtn = wait2.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@type = 'submit' and @class = 'btn btn--primary']")));
当我检查元素时,我发现其中有以下细节:-
<button class="btn btn--primary" type="submit" data-bind="enable: !processing() && !$root.accountLocked()">
<svg xmlns="http://www.w3.org/2000/svg" class="icon shape--loader" style="display: none;" viewBox="0 0 16 16" focusable="false" data-bind="visible: processing()">
<title>Processing</title>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#shape--loader" />
</svg>
Continue
</button>
抛出的错误如下:-线程"main"org. openqa.selenium.TimeoutException中的异常:等待元素可点击20秒后超时:By.xpath: //*[@type='提交'和@class='btn btn--主要']
但是对象/元素已经加载,所以不确定为什么它不能单击元素。
我还尝试了JavaScript执行器,但无济于事。
请帮我解决。提前感谢!!!
只是为了澄清一下,上面给出的XPath是唯一的吗?如果是,你是否尝试过使用JSExecator?
尝试使用以下代码:
WebElement element = driver.findElement(By.xpath("//*[@type = 'submit' and @class = 'btn btn--primary']")));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
如果很难用属性找到,那么根据按钮名称找到它。如果喜欢的页面中只有一个继续按钮。
WebElement continueBtn = wait2.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(text(),'Continue')]")));
最后我得到了解决方案。在到达解决方案之前,我尝试了显式等待,我已经将其代码粘贴到问题本身,然后使用JavaScript执行器进行尝试,但它也不起作用。以下是解决方案:-
Actions action = new Actions(driver);
action.sendKeys(Keys.ENTER).build().perform();
它工作得很好。谢谢你们所有贡献时间和努力的人。