Using Python bindings, Selenium WebDriver click() is not working sometimes.

后端 未结 7 1465
旧巷少年郎
旧巷少年郎 2021-02-02 12:27

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.

相关标签:
7条回答
  • 2021-02-02 13:02

    I ran into the above issue where the same .click() is working in all browsers(IE, Chrome and Firefox) but not working for Safari. So I tried all the possible solutions from this post and none of them worked and it doesn't even throw error.

    I tried below by substituting .click() with .submit(), which is an equivalent method and it worked not only for Safari but also for all other browsers.

    So this:

    driver.find_element_by_id('login_btn').click()

    Replaced as:

    driver.find_element_by_id('login_btn').submit()

    If above fails to work on other browsers due to any reason keep .submit() in try and except. If it fails .click() will be triggered and executed.

    Hope this helps if none of the other solutions works.

    0 讨论(0)
  • 2021-02-02 13:04

    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.

    0 讨论(0)
  • 2021-02-02 13:08

    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")
    
    0 讨论(0)
  • 2021-02-02 13:08

    I had the same issue where a two-part drop down menu selection would not generate what it's supposed to generate with proper selections. It worked when I did imported time and use time.sleep(2) between the two "click"s. (For reference I used find_element_by_xpath to find an modify the options.)

    0 讨论(0)
  • 2021-02-02 13:10

    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.

    0 讨论(0)
  • 2021-02-02 13:10

    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.

    0 讨论(0)
提交回复
热议问题