我在试着打开youtube的视频。导航到搜索结果后,我无法打开所需的链接。它不接受searchBaari的xpath。任何帮助都将不胜感激。
代码如下:
from selenium import webdriver
driver = webdriver.Chrome('/Users/souravroy/Downloads/chromedriver-2')
driver.get('https://youtube.com')
searchbox = driver.find_element_by_xpath('//*[@id="search"]')
searchbox.send_keys('Baari')
searchButton = driver.find_element_by_xpath('//*[@id="search-icon-legacy"]/yt-icon')
searchButton.click()
driver.implicitly_wait(4500)
searchBaari = driver.find_element_by_xpath('//*[@id="Baari Lyrics Translation"]/yt-formatted-string')
searchBaari.Click()发布于 2020-02-28 03:33:43
我在页面上没有找到任何带有@id="Baari Lyrics Translation"的元素。尽管有这样一个标题的链接部分匹配。尝试修改最后几行以使用此定位器:
searchBaari = driver.find_element_by_xpath('//a[contains(@title,"Baari Lyrics Translation")]')
searchBaari.click()这应该会成功,我希望它能有所帮助。祝好运。
https://stackoverflow.com/questions/60435437
复制相似问题