我需要修改这个代码。它附带了一条错误消息,说明
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="login_username"]"}
(Session info: chrome=92.0.4515.159)
以下是代码
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
# finq credentials
username = "xxxxxxx@gmail.com"
password = "xxxxxxxxx"
# initialize the Chrome driver
driver = webdriver.Chrome(executable_path=r'C:\Users\snyder\data\chromedriver.exe')
# head to finq login page
driver.get("https://www.finq.com/en/login")
# find username/email field and send the username itself to the input field
driver.find_element_by_id("login_username").send_keys(username)
# find password input field and insert password as well
driver.find_element_by_id("login_password").send_keys(password)
# click login button
driver.find_element_by_name("submit_login").click()
发布于 2021-08-28 13:57:19
它在iframe中,所以你需要在交互之前切换到它。
您可以使用以下css_selector
切换到iframe:
iframe[id='login']
在代码中:
username = "xxxxxxx@gmail.com"
driver = webdriver.Chrome(driver_path)
driver.maximize_window()
driver.implicitly_wait(5)
driver.get("https://www.finq.com/en/login")
wait = WebDriverWait(driver, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[id='login']")))
# find username/email field and send the username itself to the input field
driver.find_element_by_id("login_username").send_keys(username)
# find password input field and insert password as well
driver.find_element_by_id("login_password").send_keys(password)
# click login button
driver.find_element_by_css_selector("button[id='submit_login']").click()
导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
https://stackoverflow.com/questions/68965002
复制相似问题