Victor Semenov
Victor Semenov

Reputation: 47

How to get new page source after navigating Python Selenium

I am facing an issue. I navigate on the page via Selenium Chrome. I have timeouts and WebDriverWait as I need a full page to get JSON out of it. Then I click the navigation button with

driver.execute_script("arguments[0].click();", element)

as normal click never worked. And it is navigating OK, I see Selenium is surfing normally. No problem. But the driver.page_source remains for the first page that I got via 'get' method

All timeouts are the same as for the first page. And I see those new pages normally, but the page_source never updates.

What am I doing wrong?

Upvotes: 0

Views: 1060

Answers (1)

Jonas
Jonas

Reputation: 1769

After navigating to the new Page, you need to get the current URL by:

url = driver.current_url()

and then:

driver.get(url)
driver.getPageSource()

Upvotes: 1

Related Questions