Skip to content Skip to sidebar Skip to footer

Using Python Bindings, Selenium Webdriver Click() Is Not Working Sometimes.

I am trying to submit an input(type= button).But I am unable to update the value. Any help is appreciated. I have attached the testcase below for your reference. search for CLICK F

Solution 1:

You could try substituting .click() with .send_keys("\n"), which is equivalent to "Pressing enter while focusing on an element".

So this:

driver.find_element_by_link_text('PurchaseOrder').click()

would become this:

driver.find_element_by_link_text('PurchaseOrder').send_keys("\n")

Solution 2:

In case this is still a recurring problem for anyone else, if you have confirmed your code is correct (you've reviewed it for errors etc.) and you still find the find_element_by_...('text').click() function not working properly it is often due to your code continuing to run before the JavaScript can update the page.

A simple solution is to import time then insert the below code immediately after any click() methods:

time.sleep(2) 

The duration of the sleep timer can be whatever you choose. In my case I used 2 seconds. Hopefully that helps.

Solution 3:

I had this problem as well. Sometimes, for whatever reason webdriver didn't click the button. It was able to find the button (it didn't throw a NoSuchElementException and a WebDriverWait didn't help).

The problem with clicking the button twice was that if the first click succeed, the second one would fail (or click the submit button on the next page if it found a match!). My first attempt was to put the second click in a try/except block - this is how I found out about it clicking submit on the next page. XD And it also really slowed down my test when it couldn't find the second button.

I found some good insights at Selenium 2.0b3 IE WebDriver, Click not firing. Basically, I click on a parent element first, which seemingly does nothing. Then I click on the submit button.

Solution 4:

If the element you click() is an url. I found that taking the href properties and using driver.get(elem.get_attribute('href')) being the cleanest.

Solution 5:

I would try other element finders like className, cssSelector or something. xPath sometimes doesnt provide errors if the element isn't found. So first start by finding out if the element is really found by webdriver.

You can also try to click or use the other commands two times in a row. This already solved some of such issues.

Post a Comment for "Using Python Bindings, Selenium Webdriver Click() Is Not Working Sometimes."