gpt4 book ai didi

javascript - 如何使用 Javascript :void(0) Selenium? 单击按钮

转载 作者:行者123 更新时间:2023-11-29 21:01:47 30 4
gpt4 key购买 nike

我一直在努力,我已经尝试了很多事情。抱歉,如果我的格式不正确,但无论如何,我需要单击的相关元素是:

<button href="javascript:void(0)" id="payNewBeneficiary" class="button-new-payee">
<div class="icon">
<div></div>
</div>
<h2>Someone new</h2>
<p>Make a once-off payment or pay someone new</p>
</button>

到目前为止,我已经尝试通过 ID、cssSelector 和 xpath 查找元素。这个我也试过

Actions act = new Actions(driver); 
act.moveToElement(payNewBeneficiaryButton);
act.click(payNewBeneficiaryButton);
act.build().perform();

还有这个

((JavascriptExecutor)driver).executeScript("document.getElementById('payNewBeneficiary').click()");

还有这个

JavascriptExecutor exec = (JavascriptExecutor) driver;
exec.executeScript("arguments[0].click()", payNewBeneficiaryButton);

最佳答案

试试这些

driver.findElement(By.css("<one of the below css>")).click()

你可以试试css

button#payNewBeneficiary div div
button#payNewBeneficiary div
button#payNewBeneficiary h2
button#payNewBeneficiary p

有时监听可能在指定的子元素上

关于javascript - 如何使用 Javascript :void(0) Selenium? 单击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46101951/

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