简体   繁体   English

如何使用 Selenium 和 Python 在 https://www.deepl.com/translator 中单击复制按钮

[英]How to click on the Copy button within https://www.deepl.com/translator using Selenium and Python

i am trying to automate some translation through selenium using this url https://www.deepl.com/translator .我正在尝试使用此 url https://www.deepl.com/translator通过 selenium 自动进行一些翻译。 However I am unable to click on copy button shown in photo here.但是,我无法单击此处照片中显示的复制按钮。 red marking on button .按钮上的红色标记 Inspecting this reveals this html code检查此显示此 html 代码

<button tabindex="130" _dl-connected="1" _dl-attr="onClick: $0.doCopy" _dl-attr-type="null">
                <svg width="20" height="22" viewBox="0 0 20 22" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M16.2949 15.7893H8.59364C7.36747 15.7893 6.37793 14.7947 6.37793 13.5623V3.22705C6.37793 1.9946 7.36747 1 8.59364 1H16.3164C17.5425 1 18.5321 1.9946 18.5321 3.22705V13.5839C18.5106 14.7947 17.521 15.7893 16.2949 15.7893Z" stroke-miterlimit="10"></path>
                    <path d="M11.1966 20.9997H3.34478C2.05408 20.9997 1 19.9402 1 18.6429V7.35629C1 6.05898 2.05408 4.99951 3.34478 4.99951H11.1966C12.4873 4.99951 13.5414 6.05898 13.5414 7.35629V18.6645C13.5414 19.9402 12.4873 20.9997 11.1966 20.9997Z" fill="white" stroke-miterlimit="10"></path>
                </svg>
            </button>

Please guide on how to locate this button using both xpath(what should be tag and attribute to be used here) and one other method say css locator.请指导如何使用 xpath(此处应使用的标记和属性)和另一种方法(例如 css 定位器)来定位此按钮。 I would be obliged.我有义务。

The code I used to try and locate the button is:我用来尝试定位按钮的代码是:

cpy_btn = driver.find_elements_by_xpath('//*[@id="dl_translator"]/div[1]/div[4]/div[3]/div[4]/div[1]/button')

And later I used后来我用

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "(//button[@tabindex='130'])")))

but both didn't work.但两者都没有工作。

The error message I received is: selenium.common.exceptions.ElementClickInterceptedException: Message: Element <button> is not clickable at point (1177,601) because another element <p> obscures it我收到的错误消息是: selenium.common.exceptions.ElementClickInterceptedException: Message: Element <button> is not clickable at point (1177,601) because another element <p> obscures it

The desired element is a dynamic element so to click on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies :所需元素是动态元素,因此要单击元素,您必须为element_to_be_clickable()诱导WebDriverWait ,并且可以使用以下任一定位器策略

  • Using CSS_SELECTOR :使用CSS_SELECTOR

     driver.get('https://www.deepl.com/translator') WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.lmt__target_toolbar__copy > button"))).click()
  • Using XPATH :使用XPATH

     driver.get('https://www.deepl.com/translator') WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='lmt__target_toolbar__copy']/button"))).click()
  • Note : You have to add 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
  • Browser Snapshot:浏览器快照:

深

You can try to add 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

Then use:然后使用:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "(//textarea)[2]"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='lmt__target_toolbar__copy']/button"))).click()

Whith ActionChains:使用 ActionChains:

from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='lmt__target_toolbar__copy']/button")))).click().perform()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Selenium 和 Python 在 https://mail.protonmail.com/ 注册页面中单击创建帐户按钮 - How to click on the Create Account button within https://mail.protonmail.com/ signup page using Selenium and Python 如何使用 python 中的 selenium 在 https://in.indeed.com/ 网站中单击继续按钮? - How to click the Continue button within https://in.indeed.com/ website using selenium in python? 如何使用 Selenium ZA7F5F35426B927411FC9231B56382173 在 https://www.tempinbox.xyz/mailbox/username@domain.name 中单击验证消息和按钮 - How to click on the verification message and button within https://www.tempinbox.xyz/mailbox/username@domain.name using Selenium Python 如何使用 Selenium 和 ZA7F5F352426B628741B11 填写 https://www.nike.com/register 中的 Email 地址字段 - How to fill the Email address field within https://www.nike.com/register using Selenium and Python 如何使用 Selenium 和 Python 在 https://www.shopdisney.com/ 中找到创建帐户元素 - How to locate the Create an Account element within https://www.shopdisney.com/ using Selenium and Python 如何使用Python和Selenium访问网站https://www.aliexpress.com/后点击并关闭横幅 - How to click and close the banner after accessing the website https://www.aliexpress.com/ using Python and Selenium How to locate the First name field within shadow-root (open) within the website https://www.virustotal.com using Selenium and Python - How to locate the First name field within shadow-root (open) within the website https://www.virustotal.com using Selenium and Python 如何让Selenium在DeepL.com中发送文本 - How to make Selenium send text within DeepL.com 如何使用 Python Selenium 在 https://twitter.com 中找到登录按钮 - How locate the Sign in button within https://twitter.com using Python Selenium 如何使用Selenium和Python在URL https://maps.mapmyindia.com/direction中单击文本为“ GET ROUTES”的元素? - How to click on element with text as “GET ROUTES” within the url https://maps.mapmyindia.com/direction using Selenium and Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM