网站https://cloudwise.nl/我正在尝试点击Dit is Cloudwise
Actions action = new Actions(driver);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
WebElement menu = wait.until(ExpectedConditions.presenceOfElementLocated((By.xpath("//a[@class='sf-with-ul'][contains(text(),'Dit is Cloudwise')]"))));
WebElement submenu = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//li[@id='menu-item-6380']//a[contains(text(),'Alle Cloudwisers')]")));
action.moveToElement(menu).moveToElement(driver.findElement(By.xpath("//li[@id='menu-item-6380']//a[contains(text(),'Alle Cloudwisers')]"))).click().build().perform();
但是测试仍然通过,而且没有点击。我能做错什么呢?
要将鼠标悬停在Dit is Cloudwise
上,然后单击Alle Cludwisers
,您需要诱导WebDriver等待visibilityOfElement在()上,您可以使用以下定位器策略:
>
使用xpath:
new Actions(driver).moveToElement(new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[text()='Dit is Cloudwise']")))).build().perform();
new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='Dit is Cloudwise']//following::ul[1]/li/a"))).click();
尝试使用visibilityOfElement在
中更改presenceOfElement在
。
另外,看起来像
action.moveToElement(menu).moveToElement(driver.findElement(By.xpath("//li[@id='menu-item-6380']//a[contains(text(),'Alle Cloudwisers')]"))).click().build().perform();
可以用
action.moveToElement(menu).moveToElement(submenu).click().build().perform();
@Erthan Yumer,您可以通过以下稍微更改的方式实现初始实现:
Actions action = new Actions(driver);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
WebElement menu = wait.until(ExpectedConditions
.presenceOfElementLocated((By.xpath("//a[@class='sf-with-ul'][contains(text(),'Dit is Cloudwise')]"))));
action.moveToElement(menu)
.moveToElement(wait.until(ExpectedConditions.presenceOfElementLocated(
By.xpath("//li[@id='menu-item-6380']//a[contains(text(),'Alle Cloudwisers')]"))))
.click().build().perform();