Clicking submit button using Selenium

梦想与她 提交于 2021-01-28 09:11:14

问题


I'm very newbie at this. I'm trying to login a website using Selenium to make some web scraping but I can't succeed in clicking the submit button.

This is what I'm using:

browser.find_element_by_name("submit").click()

And this is the html form code from the web:

<div _ngcontent-ihr-c27="" class="form-group">

<button _ngcontent-ihr-c27="" class="btn-fantasy green big" gtm-action="Login_Mail" gtm-category="Interaccion" gtmeventclick="" type="submit"> Iniciar sesión </button>

</div>

Any suggestion? Maybe using another attribute in find_element_by_XXX?

Thanks!


回答1:


Induce WebDriverWait And element_to_be_clickable() And following xpath option.

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn-fantasy green big' and @type='submit'][contains(.,'Iniciar sesión')]"))).click()

OR Css selector.

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn-fantasy.green.big[type='submit']"))).click()

You need to imports following.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


来源:https://stackoverflow.com/questions/58145513/clicking-submit-button-using-selenium

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!