Selenium-Python,找不到元素

时间:2019-01-21 15:37:26

标签: python selenium automation

我刚刚使用python使用硒启动了我的第一个项目。 我的第一个任务是使用“登录到chrome”按钮登录chrome,但我无法单击它:Sign to chrome button

按钮HTML:

<paper-button class="action-button" role="button" tabindex="0" animated="" aria-disabled="false" elevation="0">
                  Sign in to Chrome
                </paper-button>

这是链接:chrome://settings/people

我尝试过:

driver = webdriver.Chrome()
driver.find_element_by_class_name('action-button').click()
driver.find_element_by_xpath('//paper-button[@class='action-button']').click()
driver.find_element_by_css_selector('paper-button.action-button').click()

什么都没有。

错误:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"paper-button:not([raised]).action-button"}

1 个答案:

答案 0 :(得分:1)

请尝试使用AutoIt点子,您可以尝试以下代码:

安装Autoit:

pip install -U pyautoit 

使用以下代码:

from selenium import webdriver
import autoit
driver = webdriver.Chrome()
driver.get("chrome://settings/")
autoit.send('{TAB}{TAB}{ENTER}')

让我知道它是否有效。