如何在Amazon登录中解决org.openqa.selenium.ElementNotVisibleException

时间:2018-01-20 16:22:29

标签: selenium

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.i中登录我正在获取SignIn Button的Element NotVisibleException,它会挂在yourOrders.how上以解决此问题

1 个答案:

答案 0 :(得分:0)

在亚马逊中尝试Sign In时,ElementNotVisibleException按钮获得了SignIn,因为您调整后的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();