Skip to content
Advertisement

Python Selenium Button Click with Class Not working

I want to login to https://in1.dashboard.clevertap.com/login.html through selenium using safari. I’m able to enter username and password however since both of them have an ID, however with any of the selenium methods to locate a button I’m not able to do click on the “Log In” button. When I try it either shows an error or open Google Login. I tried to use two classes one is the button class and the second one is span class which defines the text for the button. All of them have failed.

Here is the code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

driver = webdriver.Safari()
driver.get("https://in1.dashboard.clevertap.com/login.html")
time.sleep(5)

driver.find_element_by_id("input-14").send_keys("username@username.com")
driver.find_element_by_id("input-18").send_keys("password")

#Try-1
#driver.find_element_by_xpath("//button[@class = 'ct-button full-width v-btn v-btn--contained theme--light v-size--default primary']").click();

#Try-2
#driver.find_element_by_xpath("//[@id='app'/div/div/div/div[1]/div/div/div/form/div[4]/button.ct-button full-width v-btn v-btn--contained theme--light v-size--default primary").click()

#Try-3
#driver.find_element_by_css_selector("button.ct-button full-width v-btn v-btn--contained theme--light v-size--default primary").click()

#Try-4
#driver.find_element_by_class_name("ct-button full-width v-btn v-btn--contained theme--light v-size--default primary").click()

#Try-5
#driver.find_element_by_xpath("//button[@class = 'v-btn__content']").click();

#Try-6
#driver.find_element_by_xpath("//[@id='app'/div/div/div/div[1]/div/div/div/form/div[4]/button/span.v-btn__content").click()

#Try-7
#driver.find_element_by_css_selector("button.v-btn__content").click()

#Try-8
#driver.find_element_by_class_name("v-btn__content").click()

Advertisement

Answer

click on it using Explicit wait :

wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Log In']/..")))
element.click()

Imports :

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement