我试试:
driver = webdriver.Firefox()
driver.get('https://e.mail.ru/messages/inbox/')
...
letterTag = driver.find_element_by_css_selector("div.b-datalist__item__addr")
它给了我:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"div.b-datalist__item__addr"}
我在开发工具中看到' div.b-datalist__item__addr' ,但我无法在页面的源代码中找到它。我想它是通过javascript生成的...我需要点击这个元素才能打开一个字母。我怎么能这样做?
答案 0 :(得分:0)
Link to documentation。 我的解决方案:
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
name = input("Login: ")
password = input("Password: ")
driver = webdriver.Chrome()
driver.get('https://mail.ru/')
driver.find_element_by_id('mailbox__login')
mail_name = driver.find_element_by_id('mailbox__login')
mail_name.send_keys(name)
mail_pass = driver.find_element_by_id('mailbox__password')
mail_pass.send_keys(password)
mail_pass.submit()
# get first letter
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "a.js-href.b-datalist__item__link")))
element.click()