[英]trouble clicking on dropdown sub-menu through selenium webdriver
我正在使用 selenium webdriver 自動化一個網站。 我面臨的問題是,當我點擊一個菜單項時,子菜單會打開,(它實際上是一個放錯位置的下拉菜單,ui 問題),我可以找到我想要點擊的子菜單項的元素,但我不是能夠在出現異常時單擊:
“線程“main”org.openqa.selenium.ElementNotVisibleException 中的異常:無法單擊元素”
有什么辦法可以點擊這個子菜單項嗎?
頁面的 HTML 代碼:
<td class="menulevel1norm" id="PanelTable" onmouseover="this.className='menulevel1hl';" onmouseout="this.className='menulevel1norm'" onclick="PopupWin('Left',divMenu20111219065812407304,this,'.menuitempopuprownormal','.menuitempopuprowhighlight','','.menuitempopupscroll');">
Text - Inbound
<div id="divMenu20111219065812407304" style="border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; visibility: hidden; position: absolute;" name="actiondiv">
<div myonclick="window.parent.location.href='/smcfs/console/omreceipt.search';">
![enter image description here][4]Text - MENU_Receipt Console
我的 Webdriver Java 代碼:
public static void main(String[] args) throws IOException, InterruptedException {
Runtime rt = Runtime.getRuntime();
rt.exec("taskkill /F /IM IEDriverServer.exe /T");
WebDriver driver = UtilityMethods.driverinitialize();
driver.get("xxxx");
UtilityMethods.login(driver);
WebElement e1 = (new WebDriverWait(driver, 30)).until(ExpectedConditions.elementToBeClickable(By.id("wicket-generated-id-4")));
e1.click();
driver.switchTo().defaultContent();
driver.switchTo().frame("frame4");
String eletext;
List<WebElement> elements = driver.findElements(By.id("PanelTable"));
for(WebElement ele : elements){
eletext = ele.getText();
System.out.println(eletext);
if(eletext.equals(" Inbound ")){
ele.click();
break;
}
}
Thread.sleep(2000);
List<WebElement> elements2 = driver.findElements(By.tagName("div"));
for(WebElement ele1 : elements2){
eletext = ele1.getAttribute("myonclick");
System.out.println(eletext);
if(eletext == null){
continue; }
else if(eletext.equals("window.parent.location.href='/smcfs/console/omreceipt.search';")){
ele1.click();
break;
}
}
}
首先,等待所有元素出現在頁面上。 然后,如果元素正確可見並且不與另一個元素的其他部分重疊,則單擊將執行。 另一種方法是定位附近的適當元素,然后將指針移動到某個偏移量,然后執行單擊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.