0

I'm currently trying to use Selenium/Python/PhantomJS to scrape the results of the form below:

http://gis.vgsi.com/newhavenct/Sales.aspx

It looks like when I try to click on the search button, I get an ElementNotVisibleException error.

My code:

self.driver.find_element_by_id("MainContent_btnSearch").click()

After some digging online, it seems like the button may be hidden. Indeed, here is the relevant HTML code from the search page:

<input type="button" value="Search!" class="btn btn-primary searchTrigger" style="width: 200px;" />
<input type="submit" name="ctl00$MainContent$btnSearch" value="Search" id="MainContent_btnSearch" style="width: 200px; display: none;" />
<div id="MainContent_ctl00" style="display:none;">
</div>

I tried preceding my previous code with a click of the searchTrigger, but this is still not working:

self.driver.find_element_by_class_name("searchTrigger").click()
self.driver.find_element_by_id("MainContent_btnSearch").click()

Any advice would be greatly appreciated!

2 Answers 2

1

Requested element has attribute style="display:none;", so you need to make it visible

Try to use following code:

self.driver.execute_script('document.getElementById("MainContent_btnSearch").style.display="block";')
self.driver.find_element_by_id("MainContent_btnSearch").click()
Sign up to request clarification or add additional context in comments.

Comments

1

A portion of the screen is not visible by Selenium. It may be that another element lies on top of the one you are trying to click.

For me what always works without spending hours searching for the cause is to click using Javascript:

self.driver.execute_script("arguments[0].click();", elt)

where elt is a WebElement - e.g. returned by find_element_by_id(.). Make it a function and use wherever the problem occurs.

Edit: it is a generic answer for when it happens again, but in this particular case the other answer is probably correct.

Comments

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.