In the page below, I want to click the housing types menu so that I can select apartments and such. The menu is not revealed, but the code does not fail. It fails in the last line with the exception.
org.openqa.selenium.ElementNotVisibleException: element not visible
When I run the code in debug mode & click the menu manually, it passes. What is happening & why ?
public void dummy() {
String url = "https://sfbay.craigslist.org/search/pen/apa?hasPic=1&search_distance=25&" +
"postal=94014&nh=75&nh=80&min_price=1500&max_price=2500&bedrooms=1&bathrooms=1";
browser.get(url);
WebElement expand = browser.findElement(By.id("plusminus_housing_type"));
Actions actions = new Actions(browser);
actions.moveToElement(expand).click().perform();//ERROR ! Does not reveal housing types.
WebElement house = browser.findElement(By.id("ul_housing_type"));
WebElement apartment = house.findElement(By.xpath("//li[contains(., 'apartment')]//input"));
apartment.click();
}
When I use javascript instead of actions, the menu is revealed, but I get an exception that the "apartment" element is not clickable. To fix that, I have to click it with javascript as well as shown below:
((JavascriptExecutor) browser).executeScript("arguments[0].click();", anyElement);
Surprisingly, actions or javascript is not needed to reveal the "neighborhoods" menu.
I don't want to just make the code work. I need to understand what is happening.