1

Is there a way that I only need to wait one element to load in a site and them go to another one using selenium?

I'm crawling a site that takes too long to load everything, but the info that I need is only a text that is the first thing that load.

I'm trying something like this:

df = pd.read_csv("file.csv") 
wait =  WebDriverWait(driver, 1)

for site in df.site: 
    driver.get(site)

    search = wait.until(EC.visibility_of_any_elements_located((By.XPATH, '//div[@itemprop="recipeInstructions"]//span[@tabindex="0"]')))
    search = "".join(list(map(lambda x: x.text+"---",search)))

    if(search):
        driver.execute_script("window.stop();")

    print(search)

1 Answer 1

1

You need to wait for visibility of that specific element only.
So, in case //div[@itemprop="recipeInstructions"]//span[@tabindex="0"] is unique locator of that specific element you can use code like this:

wait = WebDriverWait(driver, 30)

for site in df.site: 
    driver.get(site)
    text_you_want_to_get_is = wait.until(EC.visibility_of_element_located((By.XPATH, '//div[@itemprop="recipeInstructions"]//span[@tabindex="0"]'))).text
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.