Earn Money in 10 days

Selenium Videos

Protractor In Selenium

Livechat

Friday, 19 December 2014

[SeleniumWebDriver] No Such Element element Exception

Many of the Time Selenium users get this Problem

org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with

At that time first you need to Check if that elements is Present or Not on which you want to click or Perform any action

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestingSubmenu {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://www.neogenomics.com/solutions-overview.htm");
//Go to that website
        driver.findElement(By.xpath("//*[@id='ctl00_Header1_HorizontalNavigation1_Menu_m0_m2']/span")).click();
//Find xpath and click
After running this code you will get this Exception Element not visible.
Solution for this 
First You need to check whether that element is Present or Not
By using this is Displayed function in Selenium WebDriver You can find element is Present or not
If that element returns true then you can perform action on it.If it returns false then it means it is a hidden element.So you need to use Mouse Hover on that element.

//Here is the code
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestingSubmenu {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://www.neogenomics.com/solutions-overview.htm");
    Boolean submenu =     driver.findElement(By.xpath("//*[@id='ctl00_Header1_HorizontalNavigation1_Menu_m0_m2']/span")).isDisplayed();
       System.out.println(submenu);
       }
}

0 comments:

Post a Comment

Popular Posts

 
subscribe
Subscribe Us
emailSubscribe to our mailing list to get the updates to your email inbox... We can't wait more to have your email in our subscribers email list. Just put your nice email in below box: