Answer the question
In order to leave comments, you need to log in
How can I make xpath search work for me?
from selenium import webdriver
import time
options = webdriver.ChromeOptions()
#открытие браузера во всю ширину экрана
options.add_argument("--start-maximized")
driver = webdriver.Chrome(
executable_path="",
options=options
)
try:
driver.get("https://rick-i-morty.online")
time.sleep(5)
play_all = driver.find_element_by_id("menu-item-3").click()
time.sleep(5)
episode = driver.find_element_by_xpath('//a[contains(@href,"https://rick-i-morty.online/episodes/3sez-1seriya161")]').click()
time.sleep(10)
play = driver.find_element_by_xpath('//*[@id="vpaid-but"]').click()
time.sleep(10)
except Exception as ex:
print(ex)
finally:
driver.close()
driver.quit()
Answer the question
In order to leave comments, you need to log in
Perhaps the element is not loaded by the time it is searched.
Try adding a line after the driver definition,
this will make selenium try to find and click on the link for 15 seconds (not wait, but try periodically).
Also make sure that the element you are trying to click is currently visible in the selenium browser; maybe you need to scroll first.driver.implicitly_wait(15)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question