gpt4 book ai didi

java - 为什么 xpath 什么都不做?

转载 作者:行者123 更新时间:2023-12-02 08:41:35 24 4
gpt4 key购买 nike

source code of login bar

    BasicConfigurator.configure();
System.setProperty("webdriver.chrome.driver","C:\\Users\\Piotrek\\projekciki\\src\\main\\java\\selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://twitter.com/login?lang=pl");
WebElement element = driver.findElement(By.xpath("/html/body/div/div/div/div[2]/main/div/div/form/div/div[1]/label/div/div[2]/div/input"));
element.sendKeys("LOGIN");

只是打开推特,什么也不做。问题出在哪里?

最佳答案

修改后的代码

BasicConfigurator.configure();   System.setProperty("webdriver.chrome.driver","C:\\Users\\Piotrek\\projekciki\\src\\main\\java\\selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.navigate("https://twitter.com/login?lang=pl");
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[contains(@name,'username_or_email')]")));
WebElement element = driver.findElement(By.xpath("//input[contains(@name,'username_or_email')]"));
element.sendKeys("LOGIN");

如果上面的 xpath 不起作用,请使用这个 -//input[contains(@name,'username_or_email' )and (@type='text')]

关于java - 为什么 xpath 什么都不做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61354825/

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