簡體   English   中英

如何使用 Selenium 和 Python 來 select 一個沒有標題的元素?

[英]How to select an element with no title using Selenium and Python?

我試圖指向此按鈕,但它似乎沒有 label 或標題。

該按鈕是另一個按鈕的子按鈕,只有在單擊第一個按鈕時才會出現。

<div class="w-dialog w-css-reset" style="background: rgba(0, 0, 0, 0.7); bottom: 0px; color: rgb(255, 255, 255); display: block; left: -39.1875px; line-height: 34px; max-height: 319.691px; opacity: 1; overflow: hidden auto; position: absolute; transition: opacity 120ms ease 0ms, transform 120ms ease 0ms; transform: scaleY(1); transform-origin: center bottom; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor:rgba(0, 0, 0, 0.7); --darkreader-inline-color:#e8e6e3; width: 117.563px;" data-darkreader-inline-bgimage="" data-darkreader-inline-bgcolor="" data-darkreader-inline-color="">
<div class="w-css-reset" style="opacity: 1; transition: opacity 100ms ease 48ms;">
<div class="w-css-reset" data-handle="shareButton__dialog" style="box-sizing: border-box; display: inline-block; height: 100%; vertical-align: bottom; width: 100%;"><ul class="w-css-reset w-css-reset-tree">
下載

我嘗試使用以下方法引用它:

WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button/div[@data-handle='shareButton__dialog']"))).click()

我也試過:

 WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button/div[@data-handle='shareButton__dialog']"))).click()

我能夠找到解決方案。 它可能不適用於其他特定情況,但對於這種情況,我能夠使用:

WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='w-css-reset' and @data-handle='shareButton__dialog']"))).click()

使用此處的修改版本: How to select an element based on a polyline using Selenium and Python?

以及以下進口:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM