本文介绍了如何在 Amazon 中使用 Selenium 和 Java 解决 org.openqa.selenium.ElementNotVisibleException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

    }

}

我正在使用上面的代码登录亚马逊.我得到了登录按钮的元素 NotVisibleException,它出现在你的订单上.如何解决这个问题


i am using above code to Sign In in Amazon.i am getting Element NotVisibleException for SignIn Button which appears after hover on yourOrders.how to resolve this

推荐答案

在 Amazon 中尝试Sign In 时,您收到 ElementNotVisibleException for SignIn> 按钮作为您调整的 定位器策略 不是唯一标识 Sign In 按钮.

While trying to Sign In in Amazon you were getting ElementNotVisibleException for SignIn Button as the Locator Strategy you had adapted wasn't uniquely identifying the Sign In button.

要在 http://www.amazon.in 中的 Sign In 按钮上 click(),您可以使用以下代码行:

To click() on Sign In button in http://www.amazon.in you can use the following line of code :

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

这篇关于如何在 Amazon 中使用 Selenium 和 Java 解决 org.openqa.selenium.ElementNotVisibleException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:57