Answer the question
In order to leave comments, you need to log in
How does this Selenium Python code work?
I have a site that is very heavy and takes a long time to load, it is necessary to make it so that as soon as the desired button is active, start working and not wait for the site to fully load, I found this code but it does not work:
from selenium import webdriver
from time import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By
t1 = time()
driver = webdriver.Chrome()
wait = WebDriverWait(driver,5)
driver.get('https://mir24.tv')
wait.until(ec.element_to_be_clickable((By.XPATH,'/html/body/div[2]/div[1]/div/ul/li[5]/a')))
inn = driver.find_element_by_xpath('/html/body/div[2]/div[1]/div/ul/li[5]/a')
inn.click()
t2 = time()
print(t2-t1)
Answer the question
In order to leave comments, you need to log in
you need to be able to write Xpath expressions without such [email protected]
[2] [5] и т.п.
1. If the site takes a long time to load, then wait is recommended to be set to at least 15 seconds.
2. You need to learn how to write XPath. Here are more than enough examples: https://www.red-gate.com/simple-talk/wp-content/up...
3. No offense, but judging by the question, you need to write code under supervision experienced colleague. Ask management to assign you a mentor. You can also ask him questions.
Also read the WebDriver doc, it's short but very informative: https://selenium-python.readthedocs.io/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question