1

Having reviewed posts on this issue before, but problem persists. http://preview.harriscountyfws.org/ is a public site, pertaining to this question.

I'm trying to click on a dropdown and select "Channel Status" from the Rainfall dropdown.

I get the following error:

Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: element not visible: Element is not currently visible and may not be manipulated

I am attaching screenshot with code, but you may also visit the site and press F12 to look at the code.

Here is my current code based on research I have done so far:

   Select dropdown = new Select(driver.findElement(By.id("siteType")));

   WebElement triggerDropDown = driver.findElement(By.className("k-i-arrow-s"));
   triggerDropDown.click();

   dropdown.selectByVisibleText("Channel Status");
   dropdown.selectByIndex(1);

Neither of the last two code statements shown work (dropdown.select...) Both result in ElementNotVisibleException.

Well that's not true, because by pressing the triggerDropDown.Click(), the choices are visible!

Click Here For Screenshot

2 Answers 2

1

use the below code:

driver.get("http://preview.harriscountyfws.org/");
driver.manage().window().maximize();
Thread.sleep(2000);//use wait using until instead of this wait

 WebElement elem = driver.findElement(By.xpath("//span[text() = 'Rainfall']"));
 elem.click();
 Thread.sleep(2000);

for(int i = 0; i <= 2; i++){//2 is used bacause u have 2 options
    Actions actions = new Actions(driver);
    actions.sendKeys(Keys.DOWN).build().perform();//press down arrow key
    Actions actions2 = new Actions(driver);
    actions2.sendKeys(Keys.ENTER).build().perform();//press enter
}

this will click on channel status button.

Sign up to request clarification or add additional context in comments.

3 Comments

Your code does work. I don't like reliance on order and keydown. I'd like to make it so that the script is more maintainable. At least it works though. That is good. I tried to vote yours up. But I couldn't because I am new and don't have "Reputation". I don't believe it is worthy of downgrading. It is a good answer. I am hoping for something better. So for now, I keep this question open.
when we write test script we try to do them in a way in which you don't have to go back and change them often. now, here, if you add items, change order of items in box, etc. things don't work as expected. Also, I could make the default not be "Rainfall" in my dropdown, but something else. Methods such as "selectbyvisibletext" would not be existent, if this is the only way. If there is some technical reason why yours is the only way, then maybe we can make friendly methods that find index of particular text, etc. -- and try to make the whole thing not rely so much on factors that change.
In loop u can send index no .... I will update my ans later so that u can reuse it ....i am not infront of my laptop now....thanks
0

This is a strange one. I could click on the dropdown easily but clicking on "Channel Status" was not working. There's something about that dropdown that is not acting "normal". I tried the typical WebDriverWait but it doesn't work. Selenium is not waiting for it properly or something else is going on. I rarely recommend Thread.sleep() but in this case I can't figure out a way around it.

The code below works.

String searchText = "Channel Status";
driver.findElement(By.cssSelector("span.k-widget.k-dropdown.k-header")).click();
Thread.sleep(1000);
driver.findElement(By.xpath("//li[text()='" + searchText + "']")).click();

4 Comments

better. I will wait until I accept answer because other people might reply and I want to see what we all can learn about this. my suspicion, and I could be wrong, is that maybe the screen is divided into panels, and you have to somehow select one or the other panel to be able to make components in that panel "visible"
JeffC. On your second line, you say "driver.findElement(By.cssSelector("span.k-widget.kdropdown.k-header")).click. Is it just finding the first occurrence of? Now that I'm ready to select something from current tab, "Rainfall in last X time" dropdown, I am having problem, because the surrounding element for that is also named "span.k-widget.kdropdown.k-header". So that presents a challenge. If it is based on finding the first occurrence of that text, then again, it is not optimal code.
Yes, it's finding the first one. If you need to select something other than the first one you'll have to change the selector.
I will accept this answer, but for possible method of handling visit: selenium.10932.n7.nabble.com/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.