def video():
driver.find_element(By.XPATH,'//a[@class="player-box"]').click()
i=driver.find_element(By.XPATH,'//txpdiv[@data-role="txp-video-wrapper"]/video')
link=i.get_attribute('src')
print(link)
运行后有如下报错
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//txpdiv[@data-role="txp-video-wrapper"]/video"}
(Session info: chrome=78.0.3904.108)
于是加个时间等待后就好了
def video():
driver.find_element(By.XPATH,'//a[@class="player-box"]').click()
time.sleep(3)
i=driver.find_element(By.XPATH,'//txpdiv[@data-role="txp-video-wrapper"]/video')
link=i.get_attribute('src')
print(link)
# 1.xpath: `.`代表当前节点; '..'代表父节点