【问题标题】:python bot Instagram Emailpython bot Instagram 电子邮件
【发布时间】:2020-11-20 18:15:35
【问题描述】:

我正在开发 Instagram 帐户创建者,但我被困住了。创建 Instagram 帐户时,您需要一个电子邮件。我正在使用 ProtonMail,并且正在使用 Selenium 进行网络自动化,但是当我进入要求您输入所需用户名的步骤时,我的代码找不到该框。 现在选择用户名框的代码如下所示:

self.driver.find_element_by_id('username').send_keys(username)
self.driver.find_element_by_id('password').send_keys(password)
self.driver.find_element_by_id('passwordc').send_keys(password)

错误如下:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate 
element: {"method":"css selector","selector":"[id="username"]"}

但用户名的 id 是正确的: id for username

密码的两行代码也有效,只是用户名无效。

我试图通过类名找到用户名框,但它不起作用。

【问题讨论】:

  • 您是否尝试过在浏览器中使用 JQuery 检查元素 JS 控制台来验证您的选择器?

标签: python bots instagram


【解决方案1】:

对于任何未来的质子邮件问题。这是一个不同的iframe,这就是为什么通常的方法不起作用。我们需要切换iframe

    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
    
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("start-maximized")
    # chrome_options.add_argument('disable-infobars')
    driver = webdriver.Chrome(options=chrome_options, executable_path='C:/bin/chromedriver.exe')
    driver.get("https://protonmail.com/")
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='btn btn-default btn-short' and @href='signup']"))).click()
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='row']//p[text()='Basic account with limited features']"))).click()
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn btn-primary btn-lg pull-right' and @id='freePlan']"))).click()
    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//div[@class='usernameWrap']//iframe[@title='Registration form']")))
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='input' and @id='username']"))).send_keys("username")

【讨论】:

  • 我试过你的代码,但还是不行。错误说:selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:{“method”:“css selector”,“selector”:“.f0n8F”}
  • 我的用户名是 ProtonMail 而不是 Instagram。
  • @peterqiu 好的..完成了。请检查。这是一个不同的iframe 问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
相关资源
最近更新 更多