【发布时间】:2018-07-20 17:51:38
【问题描述】:
我正在使用 Python3 + Selenium 登录 Instagram,我正在使用 Google Chrome。当我登录时,我总是得到 2 个弹出窗口,我试图用它们的 xpath 找到它们以关闭它们。
不幸的是 Selenium 没有找到它们,我总是收到以下错误消息:
Traceback (most recent call last):
File "mycode.py", line 61, in <module>
driver.find_element_by_xpath('/html/body/div[4]/div/div/div/div[3]/button[2]').click()
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[4]/div/div/div/div[3]/button[2]"}
我的代码:
# Load page
driver.get("https://www.instagram.com/accounts/login/")
# Login
driver.find_element_by_xpath("//div/input[@name='username']").send_keys(username)
driver.find_element_by_xpath("//div/input[@name='password']").send_keys(psw)
driver.find_element_by_xpath("//span/button").click()
print('1st popup window\n')
driver.find_element_by_xpath('/html/body/div[4]/div/div/div/div[3]/button[2]').click()
print('2nd popup window\n')
driver.find_element_by_xpath("/html/body/div[2]/div/button").click()
我直接从浏览器中检索了 xpath,所以它不应该是这个问题的原因。有谁知道如何解决这个问题? 谢谢!
【问题讨论】:
标签: python google-chrome selenium instagram nosuchelementexception