Prudhavi
Prudhavi

Reputation: 47

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("[email protected]")
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()

Upvotes: 0

Views: 385

Answers (4)

Luis Moita
Luis Moita

Reputation: 67

try this

driver.find_element_by_xpath("/html/body/div[1]/div[1]/div/div/div[1]/div[1]/div/div/div/form/div[4]/button")

PS: would be nice to have the error for better understanding

Upvotes: 0

cruisepandey
cruisepandey

Reputation: 29362

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

Upvotes: 0

itronic1990
itronic1990

Reputation: 1441

See if this works:-

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

Upvotes: 0

C. Peck
C. Peck

Reputation: 3711

It is a span, not button which has that class. try

driver.find_element_by_css_selector("span.v-btn__content").click()

alternatively you could use

driver.find_element_by_css_selector('button.ct-button.full-width.v-btn.v-btn--contained.theme--light.v-size--default.primary').click()

Upvotes: 1

Related Questions