我正在尝试通过 Selenium 和 java 解析和操作一些数据(使用 Firefox 作为浏览器,使用 Ubuntu 作为操作系统)。
HTML 代码:
...
<div id="someName1">
<div id="someName2">
<div id="someName3">
<a class="sendMessegeLink" onclick="open_win(...)" title="someText1">
<img style="padding-left:5px; vertical-align:middle" src="..."/>
someText1
</a>
</div>
<table class="areaTable">
<tbody>
<tr>
<tr>
<tr class="someName4">
<td colspan="4">
<div id="SomeUniqueId" class="someName5" style="display: block;">
<table class="someName6">
<tbody>
<tr>
<tr>
<td colspan="2">
<a class="sendMessegeLink" onclick="open_iframe('...)" title="someText2">
<img style="padding-left:5px; vertical-align:middle" src="..."/>
<!-- WANTED ("not currently visible") ELEMENT -->someText2
</a>
<span class="remark"> someText3</span>
</td>
</tr>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tr>
</tr>
</tbody>
</table>
</div>
</div>
...
我一直在尝试单击“sendMessegeLink”类的元素“someText2”:
WebElement inputElement = driver.findElement(By.xpath(".//*[@id='SomeUniqueId']/table/tbody/tr[2]/td/a"));
比 :
WebElement inputElement = driver.findElement(By.cssSelector(".personalDetailsTable .sendMessegeLink"));
而不是通过操作 DOM 显示属性(阅读后):
javascriptExecutor js = (JavascriptExecutor) driver;
WebElement w = (WebElement) js.executeScript("return document.getElementByClassName('sendMessegeLink').removeAttribute('display');");
最后只是Thread.sleep(5000)
在访问元素之前,以防万一所有内容都没有在 DOM 中加载(除了driver.manage().timeouts().implicitlyWait(sec, TimeUnit.SECONDS)
我使用的.
我明白了Element is not currently visible and so may not be interacted with