12
12
from selenium .webdriver .common .by import By
13
13
from selenium .webdriver .support .wait import WebDriverWait
14
14
from selenium .webdriver .common .keys import Keys
15
- from selenium .webdriver .common .desired_capabilities import DesiredCapabilities
16
15
from selenium .webdriver .common .action_chains import ActionChains
17
16
18
17
from selenium .common .exceptions import (
@@ -229,18 +228,17 @@ def take_snapshot(self, name):
229
228
230
229
self .driver .save_screenshot (f"{ target } /{ name } _{ self .session_id } .png" )
231
230
232
- def find_element (self , selector ):
233
- """find_element returns the first found element by the css `selector`
231
+ def find_element (self , selector , attribute = "CSS_SELECTOR" ):
232
+ """find_element returns the first found element by the attribute `selector`
234
233
shortcut to `driver.find_element(By.CSS_SELECTOR, ...)`."""
235
- return self .driver .find_element (By .CSS_SELECTOR , selector )
236
-
237
- def find_elements (self , selector ):
238
- """find_elements returns a list of all elements matching the css
239
- `selector`.
234
+ return self .driver .find_element (getattr (By , attribute .upper ()), selector )
240
235
236
+ def find_elements (self , selector , attribute = "CSS_SELECTOR" ):
237
+ """find_elements returns a list of all elements matching the attribute
238
+ `selector`
241
239
shortcut to `driver.find_elements(By.CSS_SELECTOR, ...)`.
242
240
"""
243
- return self .driver .find_elements (By . CSS_SELECTOR , selector )
241
+ return self .driver .find_elements (getattr ( By , attribute . upper ()) , selector )
244
242
245
243
def _get_element (self , elem_or_selector ):
246
244
if isinstance (elem_or_selector , str ):
@@ -430,9 +428,8 @@ def _get_wd_options(self):
430
428
def _get_chrome (self ):
431
429
options = self ._get_wd_options ()
432
430
433
- capabilities = DesiredCapabilities .CHROME
434
- capabilities ["loggingPrefs" ] = {"browser" : "SEVERE" }
435
- capabilities ["goog:loggingPrefs" ] = {"browser" : "SEVERE" }
431
+ options .set_capability ("loggingPrefs" , {"browser" : "SEVERE" })
432
+ options .set_capability ("goog:loggingPrefs" , {"browser" : "SEVERE" })
436
433
437
434
if "DASH_TEST_CHROMEPATH" in os .environ :
438
435
options .binary_location = os .environ ["DASH_TEST_CHROMEPATH" ]
@@ -455,11 +452,10 @@ def _get_chrome(self):
455
452
chrome = (
456
453
webdriver .Remote (
457
454
command_executor = self ._remote_url ,
458
- options = options ,
459
- desired_capabilities = capabilities ,
455
+ options = options
460
456
)
461
457
if self ._remote
462
- else webdriver .Chrome (options = options , desired_capabilities = capabilities )
458
+ else webdriver .Chrome (options = options )
463
459
)
464
460
465
461
# https://bugs.chromium.org/p/chromium/issues/detail?id=696481
@@ -482,28 +478,22 @@ def _get_chrome(self):
482
478
def _get_firefox (self ):
483
479
options = self ._get_wd_options ()
484
480
485
- capabilities = DesiredCapabilities .FIREFOX
486
- capabilities ["loggingPrefs" ] = {"browser" : "SEVERE" }
487
- capabilities ["marionette" ] = True
481
+ options .set_capability ("loggingPrefs" , {"browser" : "SEVERE" })
482
+ options .set_capability ("marionette" , True )
488
483
489
- # https://developer.mozilla.org/en-US/docs/Download_Manager_preferences
490
- fp = webdriver .FirefoxProfile ()
491
- fp .set_preference ("browser.download.dir" , self .download_path )
492
- fp .set_preference ("browser.download.folderList" , 2 )
493
- fp .set_preference (
484
+ options .set_preference ("browser.download.dir" , self .download_path )
485
+ options .set_preference ("browser.download.folderList" , 2 )
486
+ options .set_preference (
494
487
"browser.helperApps.neverAsk.saveToDisk" ,
495
488
"application/octet-stream" , # this MIME is generic for binary
496
489
)
497
490
return (
498
491
webdriver .Remote (
499
492
command_executor = self ._remote_url ,
500
493
options = options ,
501
- desired_capabilities = capabilities ,
502
494
)
503
495
if self ._remote
504
- else webdriver .Firefox (
505
- firefox_profile = fp , options = options , capabilities = capabilities
506
- )
496
+ else webdriver .Firefox (options = options )
507
497
)
508
498
509
499
@staticmethod
0 commit comments