问题
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