Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.7k points)

I have created a little screen scraper and everything seems to be working great, the information is being pulled and saved in a DB. The only problem I am having is sometimes Python doesn't use the driver.back() so it then tries to get the information on the wrong page and crashes. I have tried adding time.sleep(5) but sometimes it still isn't working. I am trying to optimize it to take as little time as possible. So making it sleep for 30 seconds doesn't seem to be a good solution.

1 Answer

0 votes
by (62.9k points)

This is the best solution. The back() and forward() methods aren't guaranteed to work.

driver.execute_script("window.history.go(-1)")

The JavaScript passed here gives access to the pages’ Dom to navigate to the previous URL.  I hope this resolves the issue.

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium training!

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.6k users

Browse Categories

...