如何在不使用Xpath,ID,Linktext的情况下单击此项

最好我要在此属性后单击

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选择器单击


  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()

07-28 08:10