Skip to content

Commit 06fd3f3

Browse files
author
AutomatedTester
committed
Check capabilities to decide if we have a spec complaint browser
1 parent b75702a commit 06fd3f3

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

Diff for: py/selenium/webdriver/remote/switch_to.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ def window(self, window_name):
8787
driver.switch_to.window('main')
8888
"""
8989
data = {'name': window_name}
90-
if self._driver.capabilities['w3c'] == True:
90+
if self._driver.w3c:
9191
data = {'handle': window_name}
9292
self._driver.execute(Command.SWITCH_TO_WINDOW, data)

Diff for: py/selenium/webdriver/remote/webdriver.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ def start_session(self, desired_capabilities, browser_profile=None):
138138
self.session_id = response['sessionId']
139139
self.capabilities = response['value']
140140

141-
self.capabilities["w3c"] = desired_capabilities.get("marionette", False)
141+
# Quick check to see if we have a W3C Compliant browser
142+
self.w3c = "takesElementScreenshot" in self.capabilities
142143

143144
def _wrap_value(self, value):
144145
if isinstance(value, dict):
@@ -157,7 +158,7 @@ def create_web_element(self, element_id):
157158
"""
158159
Creates a web element with the specified element_id.
159160
"""
160-
return WebElement(self, element_id, w3c=self.capabilities['w3c'])
161+
return WebElement(self, element_id, w3c=self.w3c)
161162

162163
def _unwrap_value(self, value):
163164
if isinstance(value, dict) and ('ELEMENT' in value or 'element-6066-11e4-a52e-4f735466cecf' in value):
@@ -503,7 +504,7 @@ def maximize_window(self):
503504
Maximizes the current window that webdriver is using
504505
"""
505506
command = Command.MAXIMIZE_WINDOW
506-
if self.capabilities['w3c'] == True:
507+
if self.w3c:
507508
command = Command.W3C_MAXIMIZE_WINDOW
508509
self.execute(command, {"windowHandle": "current"})
509510

@@ -641,7 +642,7 @@ def implicitly_wait(self, time_to_wait):
641642
:Usage:
642643
driver.implicitly_wait(30)
643644
"""
644-
if self.capabilities["w3c"] == True:
645+
if self.w3c:
645646
self.execute(Command.SET_TIMEOUTS,
646647
{'ms': float(time_to_wait) * 1000, 'type':'implicit'})
647648
else:
@@ -658,7 +659,7 @@ def set_script_timeout(self, time_to_wait):
658659
:Usage:
659660
driver.set_script_timeout(30)
660661
"""
661-
if self.capabilities["w3c"] == True:
662+
if self.w3c:
662663
self.execute(Command.SET_TIMEOUTS,
663664
{'ms': float(time_to_wait) * 1000, 'type':'script'})
664665
else:
@@ -690,7 +691,7 @@ def find_element(self, by=By.ID, value=None):
690691
"""
691692
if not By.is_valid(by) or not isinstance(value, str):
692693
raise InvalidSelectorException("Invalid locator values passed in")
693-
if self.capabilities['w3c'] == True:
694+
if self.w3c:
694695
if by == By.ID:
695696
by = By.CSS_SELECTOR
696697
value = '[id="%s"]' % value
@@ -716,7 +717,7 @@ def find_elements(self, by=By.ID, value=None):
716717
"""
717718
if not By.is_valid(by) or not isinstance(value, str):
718719
raise InvalidSelectorException("Invalid locator values passed in")
719-
if self.capabilities['w3c'] == True:
720+
if self.w3c:
720721
if by == By.ID:
721722
by = By.CSS_SELECTOR
722723
value = '[id="%s"]' % value
@@ -792,7 +793,7 @@ def set_window_size(self, width, height, windowHandle='current'):
792793
driver.set_window_size(800,600)
793794
"""
794795
command = Command.SET_WINDOW_SIZE
795-
if self.capabilities["w3c"] == True:
796+
if self.w3c:
796797
command = Command.W3C_SET_WINDOW_SIZE
797798
self.execute(command, {'width': int(width), 'height': int(height),
798799
'windowHandle': windowHandle})
@@ -805,7 +806,7 @@ def get_window_size(self, windowHandle='current'):
805806
driver.get_window_size()
806807
"""
807808
command = Command.GET_WINDOW_SIZE
808-
if self.capabilities['w3c'] == True:
809+
if self.w3c:
809810
command = Command.W3C_GET_WINDOW_SIZE
810811
size = self.execute(command,
811812
{'windowHandle': windowHandle})

0 commit comments

Comments
 (0)