python - 如何在不使用 Xpath Selenium Python 的情况下单击

标签 python css selenium selenium-webdriver css-selectors

如何在不使用Xpath、ID、Linktext的情况下点击这个item

最好我想点击这个属性

href="/tedsfasidnpopo/Jakpopo"

 <td>
    <a id="STa_5" data-impr="False" href="/tedsfasidnpopo/Jakpopo" rel="5">
    <span class="newfile"><span class="">Jakkpopos12</span></span>
   </a> 
</td>

最佳答案

如果不想使用Xpatch, ID, Linktex 然后使用css selector点击

td>a[ href='/tedsfasidnpopo/Jakpopo']

引入WebDriverWait并等待element_to_be_clickable()

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"td>a[ href='/tedsfasidnpopo/Jakpopo'] "))).click()

您需要导入以下库。

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

已编辑:

drewno='/tedsfasidnpopo/Jakpopo'
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"td>a[href='" + drewno + "'] "))).click()

drewno='/tedsfasidnpopo/Jakpopo'
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"td>a[href='{}']".format(drewno)))).click()

关于python - 如何在不使用 Xpath Selenium Python 的情况下单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59423699/

相关文章:

Python 将数据框中的所有值替换为其他数据框中的值

html - 动态表行对齐

php - 水印文字位置右下

jquery - jquery slider 中的自动淡化问题

java - 替代 String.join 来连接

python - padding_idx 在 nn.embeddings() 中做什么

python - OpenCV 中的自适应阈值(版本 1 - swig 版本)

python - 为什么我无法使用 Selenium 选择/单击纯文本链接?

linux - 如何同时运行多个 behave+python 测试而不出错?

python - 参数中带有比较运算符的 numpy 均值