JB Rolland
JB Rolland

Reputation: 97

Different behavior between a click Selenium and Mouse click

Current Behavior

Using this piece of code

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    browser = webdriver.Firefox()
    button_value = '/html/body/div/div[2]/div/div/div/div/div[1]/div/form/div/div[3]/div[3]/a[2]'
    .........
    browser.find_element(By.XPATH, pin_box).send_keys(pin)
    browser.find_element(By.XPATH,, button_value).click() #Click NEXT Button

on this page

enter image description here

I end up going back to the login page

Whereas if I put a break point on

browser.find_element(button_type, button_value).click()

and I click with the mouse manually enter image description here

I am going to the desired page

Expected Behavior

To end up on the desired page (i.e not the login page) via Selenium like if I was manually clicking on the next button

PS: PIN html source in case you need

Upvotes: 1

Views: 1072

Answers (2)

JB Rolland
JB Rolland

Reputation: 97

Later in my code there was a redirection of the URL. This redirection did not give the time to the click submission to be completed. The follow code fixed the issue

.......    
browser.find_element(By.XPATH, pin_box).click() #Click NEXT Button
WebDriverWait(browser, timeout).until(EC.invisibility_of_element_located((By.XPATH, pin_box))) 

Sorry and thanks for those who helped me on this

Upvotes: 0

Muzzamil
Muzzamil

Reputation: 2881

Try to click with webdriver wait or with send ENTER key on next button. As last option you can try to click with Javascript .

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//a[.='NEXT']")))
element.click()

try click using Enter or Return

element.send_keys(Keys.RETURN)

OR

element.send_keys(Keys.ENTER)

OR (try to click with Java script but without wait as it can be fail on wait)

element=browser.find_element(By.XPATH, "//a[.='NEXT']")
browser.execute_script("arguments[0].click();", element)

Upvotes: 3

Related Questions