更新时间:2023-11-21 18:11:52
要在
To click on the desired comment with text as https://julissars.itworks.com
within the url you need to induce WebDriverwait for the element to be clickable and you can use either of the following solution:
使用 PARTIAL_LINK_TEXT
:
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "julissars"))).click()
使用 CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.yt-simple-endpoint.style-scope.yt-formatted-string[href*='julissars']"))).click()
使用 XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='yt-simple-endpoint style-scope yt-formatted-string' and contains(., 'julissars')]"))).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