0

So, I am trying to scroll down till a certain text appears using the following code, however as soon as I go to page the driver quits, with the following code.

def scroll_wait():
    wait = WebDriverWait(driver, 10)
    find_elem = None
    scroll_from = 0
    scroll_limit = 3000
    while not find_elem:
        sleep(2)
        driver.execute_script("window.scrollTo(%d, %d);" % (scroll_from, scroll_from + scroll_limit))
        scroll_from += scroll_limit
        try:
            find_elem = wait.until(EC.presence_of_element_located((By.XPATH, "//h3[@class='uiHeaderTitle']")))

       except TimeoutException:
           pass
    driver.close()

I'm also trying with the following XPATH, but it just keeps on scrolling even after the text,

(By.XPATH, "//*[contains(text(), 'More About You')]")

And this is the HTML code for the text I am trying to scroll to.

 <h3 class="uiHeaderTitle">More About You</h3>
2
  • For Selenium, one good way to test is build a plain HTML page that only contains what you want (For example, a h3) and mimic the scenario. I don't really know your problem but one changes that you can try is presence_of_element_located will return true if it is in the DOM, that means it is not necessary visible, this might be the reason for it to quit immediately. Try changing to visibility_of_element_located Commented Nov 5, 2017 at 21:31
  • @AngYC that works really good, you might as well post an answer so I can accept it. Commented Nov 5, 2017 at 21:37

1 Answer 1

1

For Selenium, one good way to test is build a plain HTML page that only contains what you want (For example, a h3) and mimic the scenario. I don't really know your problem but one changes that you can try is presence_of_element_located will return true if it is in the DOM, that means it is not necessary visible, this might be the reason for it to quit immediately. Try changing to visibility_of_element_located

Hope it helps!

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.