0
我想通過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>
...
我一直在試圖點擊元素類的 「someText2」 「sendMessegeLink」 有:
WebElement inputElement = driver.findElement(By.xpath(".//*[@id='SomeUniqueId']/table/tbody/tr[2]/td/a"));
比:
WebElement inputElement = driver.findElement(By.cssSelector(".personalDetailsTable .sendMessegeLink"));
並通過操縱DOM disp在一切情況下訪問元素在DOM未加載(除了driver.manage().timeouts().implicitlyWait(sec, TimeUnit.SECONDS)
我使用之前
javascriptExecutor js = (JavascriptExecutor) driver;
WebElement w = (WebElement) js.executeScript("return document.getElementByClassName('sendMessegeLink').removeAttribute('display');");
只是
Thread.sleep(5000)
,最後:打好屬性(讀this後)。
我得到Element is not currently visible and so may not be interacted with