簡體   English   中英

為 HTML 中的子元素查找 xpath 時出錯

[英]Error in finding xpath for a sub-element in HTML

我正在使用下面的代碼

Actions action=new Actions(driver);
action.moveToElement(facultyOfCivil).build().perform();
WebElement oceanManagement=driver.findElement(By.xpath("//a[@href='https://www.annauniv.edu/iom/home.php']"));
action.moveToElement(oceanManagement).build().perform();
oceanManagement.click();

將鼠標懸停在元素上后,我無法為子元素找到 xpath,因為子元素未顯示在 HTML 中

使用JavaScriptExecutor單擊元素。 試試這個,

WebDriverWait webDriverWait = new WebDriverWait(driver, 10);

Actions actions = new Actions(webDriver);
actions.moveToElement(facultyOfCivil).build().perform();

WebElement oceanManagement = webDriverWait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id="menuItemHilite32"]")));
((JavascriptExecutor) webDriver).executeScript("arguments[0].scrollIntoView();", oceanManagement);
((JavascriptExecutor) webDriver).executeScript("arguments[0].click();", oceanManagement);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM