简体   繁体   中英

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" 

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()

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM