Getting error when trying to click on an element

Hi,

I am trying to click on Academics and then Curriculum on the website – http://law.wustl.edu/deans/index.aspx

Code:

package checkForLocators;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class Locators {

static WebDriver driver = new FirefoxDriver();

public static void main(String[] args)
{

driver.navigate().to(“http://law.wustl.edu/deans/index.aspx”);

//click on the link “curriculum” under Academics

WebElement academics = driver.findElement(By.xpath(“//a[text()=’Academics’]”));

Actions action = new Actions(driver);
action.moveToElement(academics).build().perform();

driver.findElement(By.xpath(“//a[text()=’Curriculum’]”)).click();;

}
}

Output –

The code clicks on Academics and the drop down menu is displayed.However, it is not able to locate Curriculum.Even using explicit wait did not help. Kindly provide your inputs.

Error displayed :

Exception in thread “main” org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with

Add Comment
2 Answer(s)

Hi, I resolved the above issue using the below code.

package checkForLocators;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
//import org.openqa.selenium.support.ui.WebDriverWait;

public class Locators {

static WebDriver driver = new FirefoxDriver();

public static void main(String[] args) throws Exception
{

driver.navigate().to(“http://law.wustl.edu/deans/index.aspx”);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

WebElement academics = driver.findElement(By.xpath(“//a[text()=’Academics’]”));
WebElement curriculum = driver.findElement(By.xpath(“//a[text()=’Curriculum’]”));

Actions action = new Actions(driver);
action.moveToElement(academics).perform();
sleep(2);  //Adding this function call helped resolve the issue

action.moveToElement(curriculum).click().perform();
System.out.println(“Clicked on curriculum”);
}

private static void sleep(int seconds) {
try {

Thread.sleep(seconds * 1000);
} catch (InterruptedException e) {

}
}
}

rekhanaik Train Answered on August 7, 2016.
Add Comment

package selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;

public class Exercise
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty(“webdriver.chrome.driver”, “D:\\workspaceEclipseMars\\SeleniumPrectice\\resorce\\chromedriver.exe”);
WebDriver driver = new ChromeDriver();

driver.get(“http://law.wustl.edu/deans/index.aspx”);

WebElement e = driver.findElement(By.xpath(“.//*[@id=’nav-main’]/ul/li[1]/a”));

Actions a = new Actions(driver);
a.moveToElement(e).build().perform();
Thread.sleep(1000);
a.moveToElement(driver.findElement(By.xpath(“.//*[@id=’nav-main’]/ul/li[1]/ul/li[10]/a”))).click().build().perform();

}

}

Krunal_Panchal Default Answered on August 11, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.