0

I am using Selenium to log into a HikVision IP camera web client and I am experiencing an issue. The automated browser seems to successfully log in, as it loads the next page, but when I return page_source(), it shows that the webdriver is still stuck on the log in page. I have tried implementing wait/until and implicit waits for the web page to load but it does not seem to be a loading issue, as no matter how long I wait, I get the same problem.

Here is a code snippet showing how I log in:

user = driver.find_element_by_id("username")
password = driver.find_element_by_id("password")

# log in 
user.clear()
user.send_keys("admin")
password.clear()
password.send_keys("Snipr123")

driver.find_element_by_css_selector(".btn.btn-primary.login-btn").click()

The .clear() was just to get rid of the preloaded text that was giving me issues. After the login click() the automated browser successfully loads the web client, but the webdriver doesn't, since page_source() still returns the log in page.

Any ideas on what could be going wrong would be greatly appreciated.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
sdb
  • 109
  • 5

1 Answers1

0

Once you login using the line of code:

driver.find_element_by_css_selector(".btn.btn-primary.login-btn").click()

Yneed to induce WebDriverWait for the visibility_of_element_located() of any of the visible element within the DOM Tree and then extract the page source as follows:

driver.find_element_by_css_selector(".btn.btn-primary.login-btn").click()
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CLASS_NAME, "table")))
print(driver.page_source)

Note : You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352