gpt4 book ai didi

java - 如何在 Amazon 中使用 Selenium 和 Java 解决 org.openqa.selenium.ElementNotVisibleException

转载 作者:太空宇宙 更新时间:2023-11-04 10:46:32 27 4
gpt4 key购买 nike

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

}

}
<小时/>

我正在使用上面的代码登录亚马逊。我收到登录按钮的 Element NotVisibleException,该异常在将鼠标悬停在您的订单上后出现。如何解决此问题

最佳答案

尝试在 Amazon 中登录时,您收到 SignIn 按钮的 ElementNotVisibleException,因为您采用的定位器策略无法唯一标识登录按钮。

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

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

关于java - 如何在 Amazon 中使用 Selenium 和 Java 解决 org.openqa.selenium.ElementNotVisibleException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48358375/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com