繁体   English   中英

使用 Python,Selenium webdriver click() 方法不起作用

[英]Using Python , Selenium webdriver click() method is not working

我正在使用 selenium 4 和 python 来自动化网页。 Click() 方法不起作用。 仅当路径具有 type=submit 时才能使用 submit() 方法单击按钮,但无法使用 click 方法选择链接。 如果有人知道 click() 方法单击链接的替代选项,请提供帮助。

以下是代码:


from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

s = Service("C:/Program Files/webdriver/Chrome Driver/chromedriver.exe")
driver = webdriver.Chrome(service=s)

driver.get("https://www.sololearn.com/users/login")
time.sleep(2)

#driver.find_element(By.CLASS_NAME, "sl-login-login-form").send_keys(Keys.ENTER)
#---click here fails--------
driver.find_element(By.CLASS_NAME, "sl-login-login-form").click()
#---click here fails
#driver.find_element(By.CLASS_NAME, "sl-login-login-form").submit()
#login.click()
time.sleep(5)
driver.quit()

**Also i have tried with the below code but still it is not working:**

driver.find_element(By.CLASS_NAME, "sl-login-login-form").send_keys(Keys.ENTER)
driver.find_element(By.CLASS_NAME, "sl-login-login-form").submit()
login.click()

试试下面

element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, "CLASSNAME")))

element.click();

或者

element = driver.find_element(By.CLASS_NAME, "className")
driver.execute_script("arguments[0].click();", element)

不要忘记导入

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import org.openqa.selenium.JavascriptExecutor

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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