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

How to solve "waiting for visibility of element located by By.xpath" in the code?

我的程序未能定位到登录页面下一页的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();