我正在使用下面的代码

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);

10-06 05:19