How to properly click an element in Selenium using Python?

I am trying to click an element like "AH" on this page. I am using the following code.

from selenium import webdriver

url = "http://www.oddsportal.com/soccer/brazil/serie-a/internacional-santos-vcGTTAKH/"
driver = webdriver.Firefox()
driver.get(url)
element_to_click = driver.find_element_by_link_text("AH")
element_to_click.click()

      

The problem is that after the element is clicked and a new page is loaded, it goes back to the first page.

+3


source to share


2 answers


Concentrate the element and call the action click_and_hold

(worked for me):



from selenium.webdriver import ActionChains

actions = ActionChains(driver)
actions.move_to_element(element_to_click).click_and_hold(element_to_click).perform()

      

+1


source


alecxe that works.

Just to add to the discussion here

enter image description here



So when the mouse is clicked, it calls onClick for uid (4), when we do a normal click on the element, we don’t realize that it was working on mouse down

not on mouse click

.

That's why when we use webdriver to execute element.click () it doesn't work, and when we use Action class to simulate mouse using click_and_hold

it works !!

+1


source







All Articles