简体   繁体   English

如何在Python Selenium中点击这个元素?

[英]How to click on this element in Python Selenium?

I'm trying to click this element with Python Selenium.我正在尝试使用 Python Selenium 单击此元素。 The element seems to be located within a table if that is relevant.如果相关,该元素似乎位于表格中。 I've also already tried waiting until the element is present as well, but no luck.我也已经尝试过等到元素也存在,但没有运气。 Here is the code I've written so far:这是我到目前为止编写的代码:

chrome_browser.find_element_by_xpath(f"//a[contains(text(),'90099029279')]").click()

Here is the HTML:这是 HTML:

<a href="/lightning/r/a5f3o000001A2Z2AAK/view" data-id="a5f3o000001A2Z2AAK" tabindex="-1">3418-3420 19th Street, San Francisco, CA 94110- 90099029279</a>

Any help is appreciated, thank you so much!任何帮助表示赞赏,非常感谢!

  1. Try to use CSS selector to find this element.尝试使用 CSS 选择器来查找此元素。 (I am using this way just to be sure i get correct selector) Open that page in browser, Ctrl + shift + C, then again Ctrl + shift + C to select an element in the page to inspect it, right click at the code -> Copy -> Copy selector (我使用这种方式只是为了确保我得到正确的选择器)在浏览器中打开该页面,Ctrl + shift + C,然后再次 Ctrl + shift + C 到 Z99938282F04071859941E18ZF 中的代码元素在页面上单击以检查它,右键单击页面中的代码元素-> 复制 -> 复制选择器
btn = chrome_browser.find_element_by_css_selector('css selector')
btn.click()
  1. Locate Hyperlink by Link Text通过链接文本定位超链接
driver.find_element_by_link_text('3418-3420 19th Street, San Francisco, CA 94110- 90099029279').click()
driver.find_element_by_partial_link_text('90099029279').click()

You can use pyautogui module, though you need to install it first:您可以使用 pyautogui 模块,但您需要先安装它:

pyautogui.moveTo(100, 150) # Move the mouse to XY coordinates.
pyautogui.click() 

It presses the mouse at whatever spot you want it to press (in your case, the button).它在您希望它按下的任何位置(在您的情况下为按钮)按下鼠标。 I hope this is helpful:)我希望这是有帮助的:)

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

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