gpt4 book ai didi

java - 识别网页 Selenium 上的按钮元素

转载 作者:行者123 更新时间:2023-11-28 15:58:36 24 4
gpt4 key购买 nike

我想在我的网页上找到一个讨厌的按钮。大多数其他元素我都能找到,但这个让我很头疼。

html 是:

<table class="d_FG" role="presentation">
<tbody>
<tr>
<tr id="z_t">
<td class="fct_w" colspan="2">
<div>
<input name="newAttachments_fsid" value="0" type="hidden">
<table id="z_u" class="dcs" role="presentation">
<tbody>
<tr style="border: none;">
<td colspan="3" style="padding-right:0">
<a id="z_v" class="vui-button d2l-button d2l_1_192_930" role="button" tabindex="0" aria-disabled="false">Add a File</a>
<a id="z_w" class="vui-button d2l-button d2l_1_193_372" role="button" tabindex="0" aria-disabled="false">Record Audio</a>
</td>
<td></td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>

我正在尝试定位元素:

<a id="z_v" class="vui-button d2l-button d2l_1_192_930" role="button" tabindex="0" aria-disabled="false">Add a File</a>

我尝试过各种方法,例如:

    public void add_attachment(){
driver.switchTo().defaultContent();
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

driver.findElement(By.id("z_v"))).click();

}

但是就是做不到。始终收到消息它不可见或将单击另一个元素。

我尝试使用向下滚动到元素的 javascript,但没有用。任何能帮助我的想法将不胜感激

最佳答案

您能否尝试一些其他解决方法,例如使用 ActionsjavascriptExecutor,如下所示,

WebElement btn = driver.findElement(By.id("z_v")));
Actions action = new Actions(driver);
action.click(btn).build.perform();

JavascriptExecutor js = (JavascriptExecutor)driver;
Js.executeScript("arguments[0].click()",btn);

关于java - 识别网页 Selenium 上的按钮元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40582738/

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