我正在编写以下代码,以单击文本为我的帐户的元素。它显示“元素不可见”。为了解决这个问题,我正在尝试等待,但是超时。有没有办法。您可以在下面找到我的代码:
package com.php.travels;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class LogIn {
public static void main(String[] args) {
System.setProperty(
"webdriver.chrome.driver",
"/Users/owner/desktop/chromedriver");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("https://www.phptravels.net");
try {
WebDriverWait wait=new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(
By.xpath("//li[@id ='li_myaccount']/a"))
).click();
}
catch(Throwable t){
System.out.println("The execption is: " + t);
}
finally {
System.out.println("If no exception tell me now");
}
}
} // end class