简体   繁体   中英

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.

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM