gpt4 book ai didi

testing - 代码中的 "waiting for visibility of element located by By.xpath"如何解决?

转载 作者:行者123 更新时间:2023-11-28 21:16:23 27 4
gpt4 key购买 nike

我的程序未能找到登录页面下一页中的pass-code 字段,因此我尝试通过如下等待来找到它(一段代码显示)。

我已经尝试将等待时间增加到 100,但它也不起作用。

它显示为程序在密码字段中停止,即使没有到达 sing-in 按钮。

收到的错误为:

org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: //input[@id='user-passcode'] (tried for 10 second(s) with 500 milliseconds interval)at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:81)

它总是显示在 81 中失败,无论代码...

WebElement unfield = driver.findElement(By.xpath("//input[@id='user-name']"));
Actions actions = new Actions(driver);
actions.moveToElement(unfield).click();
unfield.clear();
unfield.sendKeys("test");
driver.findElement(By.xpath("//input[@id='user-password']")).clear();
driver.findElement(By.xpath("//input[@id='user-password']")).sendKeys("test");
WebElement test = driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='SIGN IN'])[1]/following::button[1]"));
Actions actions_signinclick = new Actions(driver);
signinclick_buttonclick .moveToElement(test).click();
//this will display in next page
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='user-passcode']")));
driver.findElement(By.xpath("//input[@id='user-passcode']")).click();
driver.findElement(By.xpath("//input[@id='user-passcode']")).clear();
driver.findElement(By.xpath("//input[@id='user-passcode']")).sendKeys("1234");
WebDriverWait submit_button = new WebDriverWait(driver, 100);
submit_button.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//BUTTON[@_ngcontent-wks-c3=''][text()='SUBMIT']/self::BUTTON")));
driver.findElement(By.xpath("//BUTTON[@_ngcontent-wks-c3=''][text()='SUBMIT']/self::BUTTON")).click();

请帮我找到解决方案。

最佳答案

请试试这个。

改变这一行:

signinclick_buttonclick .moveToElement(test).click();

成为:

signinclick_buttonclick.moveToElement(test).click().build().perform();

然后将定位器//input[@id='user-passcode']更改为//*[@id='user-passcode']这个:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='user-passcode']")));
driver.findElement(By.xpath("//*[@id='user-passcode']")).click();

关于testing - 代码中的 "waiting for visibility of element located by By.xpath"如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57518473/

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