Expected condition failed: waiting for visibility of element located by By.xpath

前端 未结 3 1855
情书的邮戳
情书的邮戳 2021-01-13 03:16

I am trying to click on Sign in link on site alibaba.com

This is my test case:

public class TestCase {

    public static void main(String[] args) th         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-13 03:59

    public static void waitVisibilityOfElementLocated(WebDriver driver, String locator) {
            String key = "";
            WebElement element = null;
            try {
                key = Utility.fetchLocatorKey(locator);
            } catch (Exception e) {
                System.out.println("Exception in getText method, " + e.getMessage());
            }
    
            if (key.endsWith("id")) {
                WebDriverWait wait = new WebDriverWait(driver, 60);
                element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(locator)));
            } else if (key.endsWith("cssselector")) {
                WebDriverWait wait = new WebDriverWait(driver, 60);
                element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(locator)));
            } else if (key.endsWith("linktext")) {
                WebDriverWait wait = new WebDriverWait(driver, 60);
                element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText(locator)));
            } else if (key.endsWith("xpath")) {
                WebDriverWait wait = new WebDriverWait(driver, 60);
                element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator)));
            }
    
        }
    

提交回复
热议问题