简体   繁体   English

如何使用 Selenium 和 Python 来 select 一个没有标题的元素?

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

I am trying to point at this button but it does not seem to have a label or title.我试图指向此按钮,但它似乎没有 label 或标题。

The button is a sub-button of another, and will only come up when the first button is clicked.该按钮是另一个按钮的子按钮,只有在单击第一个按钮时才会出现。

<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">
Download 下载

I have tried referencing it using:我尝试使用以下方法引用它:

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

And I also tried:我也试过:

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

I was able to find a solution.我能够找到解决方案。 It may not work in other specific cases, but for this case I was able to use:它可能不适用于其他特定情况,但对于这种情况,我能够使用:

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

Using a modified version from here: How to select an element based on a polyline using Selenium and Python?使用此处的修改版本: How to select an element based on a polyline using Selenium and Python?

and with the following imports:以及以下进口:

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