【问题标题】:selenium common exception:timeout exception message how to rectify itselenium 常见异常:超时异常消息如何纠正
【发布时间】:2020-08-30 20:45:00
【问题描述】:
from selenium.webdriver.common.by import By 
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup as b
import time

class Login:
    def __init__(self, driver, username, password):
        self.driver = driver
        self.username = username
        self.password = password
    def signin(self):
        print('opening')
        self.driver.get('https://www.instagram.com/accounts/login/?source=auth_switcher')
        uid = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, '#react-root > section > main > article > div.rgFsT > div:nth-child(1) > div > form > div:nth-child(2) > div > label > input')))
        uid.click()
        uid.send_keys(self.username)
        pswd = self.driver.find_elements_by_css_selector('#react-root > section > main > article > div.rgFsT > div:nth-child(1) > div > form > div:nth-child(3) > div > label > input')
        pswd.click()
        pswd.send_keys(self.password)
        btn = self.driver.find_elements_by_css_selector('#react-root > section > main > article > div.rgFsT > div:nth-child(1) > div > form > div:nth-child(4)')
        btn.click()
        time.sleep(3)

【问题讨论】:

  • 我们需要查看您的源代码。您能否尝试在 Chrome 开发工具中粘贴您的 CSS 选择器并查看该元素是否突出显示。我猜要么元素未在 10 秒内加载,要么 CSS 选择器不正确。是否也可以提供HTML?所以我们可以看看它,看看我们是否可以缩短选择器

标签: python selenium selenium-webdriver selenium-chromedriver browser-automation


【解决方案1】:

模块“selenium.webdriver.support.expected_conditions”没有“presence_of_elements_located”成员;也许'presence_of_element_located'?

uid = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, '#react-root > section > main > div > article > div > div:nth-child(1) > div > form > div:nth-child(2) > div > label > input')))
        uid.click()
        uid.send_keys(self.username)

【讨论】:

    猜你喜欢
    • 2021-03-19
    • 2020-07-19
    • 2013-06-30
    • 2021-02-25
    • 2017-04-19
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    相关资源
    最近更新 更多