Ray
Ray

Reputation: 1

How to click html 'button class' using selenium at python

I'd like to click the button using python selenium but have failed to do so. How to click "나중에 하기" with a code? I've tried with driver.find_element_by_link_text but didn't work... please help

elem = driver.find_element_by_link_text('나중에 하기')
elem.send_keys(Keys.RETURN)

button class="aOOlW  bIiDR  " tabindex="0">설정</button"
button class="aOOlW   HoLwm " tabindex="0">나중에 하기</button"

Upvotes: 0

Views: 204

Answers (2)

Guy
Guy

Reputation: 50809

find_element_by_link_text works only on <a> tags. Try to locate the element by xpath instead

driver.find_element_by_xpath('//button[.="나중에 하기"]').click()

Or use class instead to locate by text

driver.find_element_by_class_name('HoLwm').click()

Upvotes: 1

QHarr
QHarr

Reputation: 84465

You could try waiting for the element to be clickable and combine css selectors for tag and class

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.HoLwm"))).click()

imports

from selenium import webdriver
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

Related Questions