0
Actions action = new Actions(driver);
WebElement we = driver.findElement(By.xpath("//*[@id=\"container\"]/div/div[2]/div/ul/li[1]/span"));
action.moveToElement(we).moveToElement(driver.findElement(By.xpath("//*[@id=\"container\"]/div/div[2]/div/ul/li[1]/ul/li/ul/li[1]/ul/li[1]/a[@href='/mobile-phones-store?otracker=nmenu_sub_Electronics_0_Mobiles']"))).click().build().perform();  

我正在尝试使用 xpath 悬停并单击。该代码没有抛出任何错误,但悬停后仍然无法执行单击选项。

4

1 回答 1

0

试试下面的代码片段。我已经用 chrome 驱动程序对其进行了测试,并且工作正常。

WebElement electronics_menuname = driver.findElement(By.xpath("//span[contains(text(),'Electronics')]"));
        Actions builder = new Actions(driver);
        builder.moveToElement(electronics_menuname).build().perform();

        WebElement mobile_menu_button = driver.findElement(By.xpath("//li[@class='_1KCOnI _2BfSTw _1h5QLb _3ZgIXy']//a[contains(text(),'Mobiles')]"));
        new WebDriverWait(driver,20).until(ExpectedConditions.elementToBeClickable(mobile_menu_button)).click();
于 2019-08-18T17:16:57.617 回答