首页 > 解决方案 > Python Selenium ng-click 动作

问题描述

我一直在 Stackoverflow 或 Google 上寻找解决方案,但不幸的是我找不到任何解决方案。我正在尝试在网站上进行 webscrape,但我无法使用 Python + Selenium + Chrome webdriver 点击按钮。

网站上的 HTML 代码:

<button type="button" ng-click="launch()" title="HTTP/HTTPS: WebSQL">
<div class="flex-column-centered">
    <f-icon class="bookmark-icon-large fa-globe" ng-class="TYPE_MAP[bookmark.apptype].icon"></f-icon>
    <span class="ng-binding">WebSQL</span>
</div> </button>

我知道那是 AngularJS,我尝试了 CSS 选择器和 Xpath,但这些似乎都不适用于我的情况。任何帮助,将不胜感激!

标签: pythonhtmlseleniumselenium-chromedriverangularjs-ng-click

解决方案


你能试试这个 xpath 吗:

//span[text()='WebSQL']/../..

我建议你有这样的明确等待:

WebDriverWait(driver , 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='WebSQL']/../.."))).click()

进口:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

推荐阅读