user10813834
user10813834

Reputation: 43

How to click a span text using selenium Python

I have been trying to use selenium python to click the continue button in Login Page from the below link.

https://www.makemytrip.com

I have tried several selectors, xpath..nothing seems working for me.

This is the element I am trying to click on:

driver.find_element_by_xpath("//span[text()='Continue']").click()

Tried with Div class too:

driver.find_element_by_xpath("//div[contains(@class, 'appendBottom25 ')]")

I expect the selenium to click the continue button and to load to the password page

Upvotes: 1

Views: 6605

Answers (3)

Yun
Yun

Reputation: 1042

I think you should click on "button".

Try to use xpath below:

//button[./span[text()='Continue']]

And use explicit wait to wait element to be clickable.

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[./span[text()='Continue']]"))).click()

Upvotes: 0

Pritam Maske
Pritam Maske

Reputation: 2770

You are using right xpath

Solution :

perform the click operation twice :

element =driver.find_element_by_xpath("//span[text()='Continue']")

element.click()
element.click()

It is a strange solution but .. I got solved this problem same way only.

Upvotes: 3

Medanko
Medanko

Reputation: 746

try this one:

driver.find_element_by_xpath("//*[@id="SW"]/div[2]/div[2]/div[2]/section/form/div[2]/button/span").click()

if you choose to find element by xpath you have to pass as argument the xpath. (you right-click on the continue button > inspect > and then right click on the elemnt that marked > copy xpath)

Upvotes: 0

Related Questions