【问题标题】:How to resolve org.openqa.selenium.ElementNotVisibleException using Selenium with Java in Amazon Sign In如何在 Amazon 中使用 Selenium 和 Java 解决 org.openqa.selenium.ElementNotVisibleException
【发布时间】:2018-06-29 17:08:40
【问题描述】:
package newpackage;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;

public class OpenAmazon {

    public static void main(String[] args) {

        WebDriver driver;
        System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\chromedriver_win32\\chromedriver.exe");
        driver=new ChromeDriver();

        driver.get("http://www.amazon.in");

        List<WebElement> yourOrders= driver.findElements(By.cssSelector("span[class='nav-line-2']"));

    //third element is the your orders
        WebElement yourOrder=yourOrders.get(2);
    //mouse hover on it to get the sign button
        Actions act=new Actions(driver);    
        act.moveToElement(yourOrder).build();   

        //click on SignIn button
        List<WebElement> signIn= driver.findElements(By.cssSelector("span[class='nav-action-inner']"));
        signIn.get(0).click();

    }

}

我正在使用上面的代码在 Amazon 中登录。我在将鼠标悬停在 yourOrders 上后出现登录按钮的 Element NotVisibleException。如何解决此问题

【问题讨论】:

    标签: java selenium selenium-webdriver xpath webdriver


    【解决方案1】:

    在亚马逊尝试Sign In 时,您会得到SignIn 按钮的ElementNotVisibleException,因为您适应的Locator Strategy 并不是唯一标识Sign In 按钮。

    click()http://www.amazon.in中的登录按钮,您可以使用以下代码行:

    driver.findElement(By.xpath("//a[@class='nav-a nav-a-2' and @id='nav-link-yourAccount']/span[@class='nav-line-1']")).click();
    

    【讨论】:

      猜你喜欢
      • 2018-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-23
      • 2023-03-27
      • 2020-05-12
      • 2014-05-04
      相关资源
      最近更新 更多