Gita
Gita

Reputation: 3

Selenium Webdriver - unable to select an option from the list box

I am trying to select an option Pune(PNQ) from "Leaving from" list box of this page http://book.spicejet.com/

driver.get("http://book.spicejet.com");
Thread.sleep(50000);
Select S = new Select(driver.findElement(By.id("ControlGroupSearchView_AvailabilitySearchInputSearchVieworiginStation1")));
S.selectByValue("PNQ");

But I am receiving this error:

org.openqa.selenium.ElementNotVisibleException

I am new to Selenium. Please help.

Upvotes: 0

Views: 2581

Answers (1)

ddavison
ddavison

Reputation: 29032

Straight from the Selenium source -

/**
 * Thrown to indicate that although an element is present on the DOM, it is not visible, and so is
 * not able to be interacted with.
 */
public class ElementNotVisibleException...

As it says, the element is there on the DOM, but not visible to operate with. If there a preemptive action you have to take before that element exists, then do that.

An example would be Google image searches. When you click on an image, a black box appears with the picture. That element is always there, but you have to click on an image to make it appear.

Sounds like the same thing is happening with your select box.

Edit

I took the liberty of further looking at your particular issue.. it looks like that site hides that <select> tag because it's filled in by some jQuery stuff.

Instead of using the select tag and selecting by value, do,

driver.findElement(By.id("ControlGroupSearchView_AvailabilitySearchInputSearchVieworiginStation1_CTXT").sendKeys("PNQ");
driver.findElement(By.cssSelector("a[value='PNQ']").click();

Hope this helps.

Upvotes: 1

Related Questions