Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 尝试将鼠标悬停在菜单上并单击子菜单中的链接,但运气不佳_Selenium_Selenium Webdriver - Fatal编程技术网

Selenium 尝试将鼠标悬停在菜单上并单击子菜单中的链接,但运气不佳

Selenium 尝试将鼠标悬停在菜单上并单击子菜单中的链接,但运气不佳,selenium,selenium-webdriver,Selenium,Selenium Webdriver,我正在学习将鼠标悬停在菜单上,然后单击子菜单中的链接 场景是转到URL“”,将鼠标悬停在“Hello登录”上,然后单击链接“从这里开始” 我可以使用moveToElement()将鼠标悬停在“Hello登录”上,子菜单正在打开,但无法单击“从这里开始”链接 这是我的密码 WebElement signUp = driver.findElement(By.id("nav-link-yourAccount")); Actions action = new Actions(driver); actio

我正在学习将鼠标悬停在菜单上,然后单击子菜单中的链接

场景是转到URL“”,将鼠标悬停在“Hello登录”上,然后单击链接“从这里开始”

我可以使用moveToElement()将鼠标悬停在“Hello登录”上,子菜单正在打开,但无法单击“从这里开始”链接

这是我的密码

WebElement signUp = driver.findElement(By.id("nav-link-yourAccount"));
Actions action = new Actions(driver);
action.moveToElement(signUp).build().perform();

WebElement startHere = 
wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Start here")));
startHere.click();

链接文本的末尾包含一个点,您在代码中遗漏了它,请按.linkText(“从这里开始”)或.partialLinkText(“从这里开始”)尝试下面修改的代码,它将按预期工作。首先,您可以找到新的Customer Div,然后直接访问下面的start here链接

WebElement signUp = driver.findElement(By.id("nav-link-yourAccount"));
Actions action = new Actions(driver);
action.moveToElement(signUp).build().perform();

WebElement newCustomer=driver.findElement(By.id("nav-flyout-ya-newCust"));
newCustomer.findElement(By.xpath(".//a")).click();

访问URL
https://www.amazon.in
然后将鼠标悬停在Hello Sign-in上,然后单击链接从这里开始。您必须诱导WebDriverWait,使文本为Hello Sign-in的元素可见,然后将鼠标悬停在其上,然后为文本为的元素导入WebDriverWait,从这里开始。可单击,您可以使用以下解决方案:

  • 代码块:

    System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    driver.get("https://www.amazon.in/");
    WebElement signUp = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("nav-link-yourAccount")));
    new Actions(driver).moveToElement(signUp).build().perform();
    new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.linkText("Start here."))).click();
    
  • 浏览器快照:


谢谢。您刚刚发布了一个简单等待的简短教程。感谢您提供的解决方案。连锁搜索。棒 极 了从下面的三个答案中学到了三件事。我对拼写的无知。2.显式等待的用法。3.链接搜索以定位元素。谢谢。三个答案解决了我的问题。我无法决定对哪一个进行升级投票。你可以对多个答案进行升级投票,如果这对你的问题真的有帮助的话。是的,升级投票但不会反映出来,因为我的声誉不足以进行升级投票。你需要至少15个声誉来进行升级投票。然而,一旦你有足够的声誉,你就可以进行投票。