Selenium web driver: cannot be scrolled into view

前端 未结 4 1156
天涯浪人
天涯浪人 2020-11-29 10:13

I am using Selenium IDE and Selenium web driver testng in eclipse .. my testing is against ZK application ..

the test case works fine on Selenium IDE ..



        
4条回答
  •  时光取名叫无心
    2020-11-29 10:56

    Naif,

    Actually, your above question is different than the actual question hence you should have asked it as a separate question. Still, I'm answering to your previous question.

    The error is because the element you're trying to click on isn't visible. Before you click on element, it should be visible. You can do this by following -

    WebElement element = driver.findElement(By.xpath("//div[2]/div[2]"));
    WebDriverWait wait = new WebDriverWait(driver, 20); //here, wait time is 20 seconds
    
    wait.until(ExpectedConditions.visibilityOf(element)); //this will wait for elememt to be visible for 20 seconds
    element.click(); //now it clicks on element
    

    If above doesn't work, you can click on element by executing javascript(but this isn't a good practice)

    JavascriptExecutor js = (JavascriptExecutor)driver;
    js.executeScript("arguments[0].click();", element);
    

提交回复
热议问题