How to make element visible in selenium java

Viewed 1059

When I am trying to execute below code its giving me exception as:-org.openqa.selenium.ElementNotVisibleException: element not visible

 WebElement elem = newDriver.findElement(By.name("loginId"));
    elem.get(0).clear();
    elem.get(0).sendKeys("asd");

even though element is present.

For more details see the below image.

enter image description here

I am trying to access input box below account label but its giving me exception as element is not visible.

I already used Actions tag and JavascriptExecutor

Any suggestions.

1 Answers

The interested element is inside an iframe:

enter image description here

So, before, you have to switch to the iframe:

    WebElement iframe= driver.findElement(By.id("alibaba-login-box"));
    driver.switchTo().frame(iframe);

If you want to go "out" the iframe:

driver.switchTo().defaultContent();

The entire code:

    WebElement iframe= driver.findElement(By.id("alibaba-login-box"));
    driver.switchTo().frame(iframe);
    WebElement elem = driver.findElement(By.id("fm-login-id"));
    elem.clear();
    elem.sendKeys("asd");

    //when you want to return to the defaultContent
    driver.switchTo().defaultContent();
Related