This is one of my first attempt to write a python script-
I am trying to run a test case on localhost that is on IIS server. This is the local environment. I made following changes:
- Changed Firefox Settings to 'No proxy'
- Configured and redirected url in IIS such that '127.0.0.1' points to the website. So, entering 127.0.0.1 in browser redirects to the local website in IIS
I have to always 'Allow'/'Block' geoLocation alert and Firefox requires browser capabilities to set such.
Hence,
- I created a new Firefox profile
- Set it's preference such that is 'allows' alert for geoLocation services
- Set socks proxy to 127.0.0.1
- Set Desired Capabilities
Following is the code:
class CheckGeoLocationsDropDown():
def test_check_geo_locations_dropdown(self):
try:
selenium_profile = webdriver.FirefoxProfile()
# media.navigator.permission.disabled is set in the FF to True, however, as FF creates new Profile, do not know how to do.
#selenium_profile.set_preference('media.navigator.permission.disabled', True)
# Setting no proxy or socks proxy to 127.0.0.1 and port 80
selenium_profile.set_preference("network.proxy.socks", '127.0.0.1')
selenium_profile.set_preference("network.proxy.socks_port", 80)
selenium_profile.update_preferences()
baseUrl = 'http://127.0.0.1:80'
# os.environ['no_proxy'] = '127.0.0.1:80'
# Create a desired capabilities object as a starting point.
capabilities = DesiredCapabilities.FIREFOX.copy()
capabilities['platform'] ="WINDOWS"
capabilities['version'] = "7"
capabilities['nativeEvents'] = True
capabilities['unexpectedAlertBehaviour'] = 'Accept'
# Instantiate an instance of Remote WebDriver with the desired capabilities.
driver = webdriver.Remote(desired_capabilities=capabilities,
command_executor='http://127.0.0.1:80',
browser_profile=selenium_profile)
#driver.find_element_by_css_selector('#exceptionDialogButton')
driver.maximize_window()
driver.get(baseUrl)
# driver.find_element_by_css_selector('#exceptionDialogButton')
# _select_geo_locations_dropdown(driver)
# print(driver.title)
driver.implicitly_wait(5)
driver.refresh()
driver.close()
item = '*'
print(item * 40 + 'Geo Locations Dropdown selected successfully' + item * 40)
except NoSuchElementException:
print("Couldn't Run Script")
ff = CheckGeoLocationsDropDown()
ff.test_check_geo_locations_dropdown()
Below is the error I am getting
I tried to read through Python document, however I am unable to find what is that I am doing wrong here. Please accept my apologies if I have not included enough information. Any help would be appreciated.
UPDATE 1/29/2018:
So I need to detect geolocation permission request alert. I should be able to allow/block the geolocation sharing. Since Selenium creates a new FF profile for every instance, I set the preference selenium_profile.set_preference('media.navigator.permission.disabled', True)
I've now added to lines
capabilities['nativeEvents'] = True
capabilities['unexpectedAlertBehaviour'] = 'Accept'
It's still throwing the same error.
REFERENCES USED: