Python Selenium: Still Struggling with grasping how Profiles and Options work: Trying to disable The Firefox popup Password Manager

Viewed 80

I am very new to Python and Selenium. I am working on a script that I can run to access a web site and book a session. What is still killing me is the Firefox pop up Password Manager. How do I dismiss the password manager pop up, or stop it from popping up at all?

If I manually dismiss the Password Manager, the script executes just fine, working as as expected.

This is the image: enter image description here

However, if I do not manually dismiss it, the script does not dismiss it either, and the bulk of the HTML of the last page does not display, and I get these errors. It seems to confirm that the find_element_by-xpath command can't find the element, which is logical if the HTML code is unavailable.

return self.find_element(by=By.XPATH, value=xpath) File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element 'value': value})['value'] File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //ul/li[@data-index='3']

After some research, I added a section with the key lines of:

profile.set_preference("dom.disable_beforeunload", True)
driver = webdriver.Firefox(firefox_profile = profile

This seems to be syntactically correct, as I am getting no errors for those lines of code, but the script has the same flaw whether I use those lines or not (comment them out). Any idea what is wrong?

The entire code is:

import datetime
import time
from selenium import webdriver

#Using Firefox to access the Web
profile = webdriver.FirefoxProfile()
options = webdriver.FirefoxOptions()

profile.set_preference("dom.disable_beforeunload", True)
driver = webdriver.Firefox(firefox_profile = profile)
driver.maximize_window()

# Open the website
driver.get('https://www.awebsite.com/book-something.html#no-redirect')

# click on the sign in tab to get Login Window
driver.find_element_by_class_name('c-header__login-text').click()

# finding the Login Window User ID Box and sending the Login ID
User_ID = driver.find_element_by_class_name('js-login-email')
User_ID.send_keys('xxxx')

#Finding the Login Window Password Box and sending the Password
Password = driver.find_element_by_class_name('js-login-password')
Password.send_keys('yyyy')

#Finding the Login Window Log-In Button and Clicking on it
driver.find_element_by_class_name('js-login-submit').click()

#Pause a few seconds until the My Account Button appears
time.sleep(5)

#Find the unordered list that contains the 4th day (data-index 3) and then click on the element that is the 4th day
#Seven_Days = driver.find_element_by_xpath('c-schedule-calendar__unordered-list-toggle')
driver.find_element_by_xpath("//ul/li[@data-index='3']").click()
1 Answers

You should set profile preferences to FALSE.

PYTHON:

profile.set_preference("dom.webnotifications.enabled", False)

Related