Guest User

Untitled

a guest
Aug 5th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.59 KB | None | 0 0
  1. This chapter cover all the interfaces of Selenium WebDriver.
  2.  
  3. Recommended Import Style
  4.  
  5. The API definitions in this chapter shows the absolute location of classes. However the recommended import style is as given below:
  6.  
  7. from selenium import webdriver
  8. Then, you can access the classes like this:
  9.  
  10. webdriver.Firefox
  11. webdriver.FirefoxProfile
  12. webdriver.Chrome
  13. webdriver.ChromeOptions
  14. webdriver.Ie
  15. webdriver.Opera
  16. webdriver.PhantomJS
  17. webdriver.Remote
  18. webdriver.DesiredCapabilities
  19. webdriver.ActionChains
  20. webdriver.TouchActions
  21. webdriver.Proxy
  22. The special keys class (Keys) can be imported like this:
  23.  
  24. from selenium.webdriver.common.keys import Keys
  25. The exception classes can be imported like this (Replace the TheNameOfTheExceptionClass with actual class name given below):
  26.  
  27. from selenium.common.exceptions import [TheNameOfTheExceptionClass]
  28. Conventions used in the API
  29.  
  30. Some attributes are callable (or methods) and others are non-callable (properties). All the callable attributes are ending with round brackets.
  31.  
  32. Here is an example for property:
  33.  
  34. current_url
  35.  
  36. URL of the current loaded page.
  37.  
  38. Usage:
  39.  
  40. driver.current_url
  41. Here is an example for a method:
  42.  
  43. close()
  44.  
  45. Closes the current window.
  46.  
  47. Usage:
  48.  
  49. driver.close()
  50. 7.1. Exceptions
  51. Exceptions that may happen in all the webdriver code.
  52.  
  53. exception selenium.common.exceptions.ElementNotSelectableException(msg=None, screen=None, stacktrace=None)
  54. Bases: selenium.common.exceptions.InvalidElementStateException
  55.  
  56. Thrown when trying to select an unselectable element.
  57.  
  58. For example, selecting a ‘script’ element.
  59.  
  60. exception selenium.common.exceptions.ElementNotVisibleException(msg=None, screen=None, stacktrace=None)
  61. Bases: selenium.common.exceptions.InvalidElementStateException
  62.  
  63. Thrown when an element is present on the DOM, but it is not visible, and so is not able to be interacted with.
  64.  
  65. Most commonly encountered when trying to click or read text of an element that is hidden from view.
  66.  
  67. exception selenium.common.exceptions.ErrorInResponseException(response, msg)
  68. Bases: selenium.common.exceptions.WebDriverException
  69.  
  70. Thrown when an error has occurred on the server side.
  71.  
  72. This may happen when communicating with the firefox extension or the remote driver server.
  73.  
  74. exception selenium.common.exceptions.ImeActivationFailedException(msg=None, screen=None, stacktrace=None)
  75. Bases: selenium.common.exceptions.WebDriverException
  76.  
  77. Thrown when activating an IME engine has failed.
  78.  
  79. exception selenium.common.exceptions.ImeNotAvailableException(msg=None, screen=None, stacktrace=None)
  80. Bases: selenium.common.exceptions.WebDriverException
  81.  
  82. Thrown when IME support is not available. This exception is thrown for every IME-related method call if IME support is not available on the machine.
  83.  
  84. exception selenium.common.exceptions.InvalidCookieDomainException(msg=None, screen=None, stacktrace=None)
  85. Bases: selenium.common.exceptions.WebDriverException
  86.  
  87. Thrown when attempting to add a cookie under a different domain than the current URL.
  88.  
  89. exception selenium.common.exceptions.InvalidElementStateException(msg=None, screen=None, stacktrace=None)
  90. Bases: selenium.common.exceptions.WebDriverException
  91.  
  92. exception selenium.common.exceptions.InvalidSelectorException(msg=None, screen=None, stacktrace=None)
  93. Bases: selenium.common.exceptions.NoSuchElementException
  94.  
  95. Thrown when the selector which is used to find an element does not return a WebElement. Currently this only happens when the selector is an xpath expression and it is either syntactically invalid (i.e. it is not a xpath expression) or the expression does not select WebElements (e.g. “count(//input)”).
  96.  
  97. exception selenium.common.exceptions.InvalidSwitchToTargetException(msg=None, screen=None, stacktrace=None)
  98. Bases: selenium.common.exceptions.WebDriverException
  99.  
  100. Thrown when frame or window target to be switched doesn’t exist.
  101.  
  102. exception selenium.common.exceptions.MoveTargetOutOfBoundsException(msg=None, screen=None, stacktrace=None)
  103. Bases: selenium.common.exceptions.WebDriverException
  104.  
  105. Thrown when the target provided to the ActionsChains move() method is invalid, i.e. out of document.
  106.  
  107. exception selenium.common.exceptions.NoAlertPresentException(msg=None, screen=None, stacktrace=None)
  108. Bases: selenium.common.exceptions.WebDriverException
  109.  
  110. Thrown when switching to no presented alert.
  111.  
  112. This can be caused by calling an operation on the Alert() class when an alert is not yet on the screen.
  113.  
  114. exception selenium.common.exceptions.NoSuchAttributeException(msg=None, screen=None, stacktrace=None)
  115. Bases: selenium.common.exceptions.WebDriverException
  116.  
  117. Thrown when the attribute of element could not be found.
  118.  
  119. You may want to check if the attribute exists in the particular browser you are testing against. Some browsers may have different property names for the same property. (IE8’s .innerText vs. Firefox .textContent)
  120.  
  121. exception selenium.common.exceptions.NoSuchElementException(msg=None, screen=None, stacktrace=None)
  122. Bases: selenium.common.exceptions.WebDriverException
  123.  
  124. Thrown when element could not be found.
  125.  
  126. If you encounter this exception, you may want to check the following:
  127. Check your selector used in your find_by...
  128. Element may not yet be on the screen at the time of the find operation,
  129. (webpage is still loading) see selenium.webdriver.support.wait.WebDriverWait() for how to write a wait wrapper to wait for an element to appear.
  130.  
  131. exception selenium.common.exceptions.NoSuchFrameException(msg=None, screen=None, stacktrace=None)
  132. Bases: selenium.common.exceptions.InvalidSwitchToTargetException
  133.  
  134. Thrown when frame target to be switched doesn’t exist.
  135.  
  136. exception selenium.common.exceptions.NoSuchWindowException(msg=None, screen=None, stacktrace=None)
  137. Bases: selenium.common.exceptions.InvalidSwitchToTargetException
  138.  
  139. Thrown when window target to be switched doesn’t exist.
  140.  
  141. To find the current set of active window handles, you can get a list of the active window handles in the following way:
  142.  
  143. print driver.window_handles
  144. exception selenium.common.exceptions.RemoteDriverServerException(msg=None, screen=None, stacktrace=None)
  145. Bases: selenium.common.exceptions.WebDriverException
  146.  
  147. exception selenium.common.exceptions.StaleElementReferenceException(msg=None, screen=None, stacktrace=None)
  148. Bases: selenium.common.exceptions.WebDriverException
  149.  
  150. Thrown when a reference to an element is now “stale”.
  151.  
  152. Stale means the element no longer appears on the DOM of the page.
  153.  
  154. Possible causes of StaleElementReferenceException include, but not limited to:
  155. You are no longer on the same page, or the page may have refreshed since the element
  156. was located. * The element may have been removed and re-added to the screen, since it was located. Such as an element being relocated. This can happen typically with a javascript framework when values are updated and the node is rebuilt. * Element may have been inside an iframe or another context which was refreshed.
  157.  
  158. exception selenium.common.exceptions.TimeoutException(msg=None, screen=None, stacktrace=None)
  159. Bases: selenium.common.exceptions.WebDriverException
  160.  
  161. Thrown when a command does not complete in enough time.
  162.  
  163. exception selenium.common.exceptions.UnableToSetCookieException(msg=None, screen=None, stacktrace=None)
  164. Bases: selenium.common.exceptions.WebDriverException
  165.  
  166. Thrown when a driver fails to set a cookie.
  167.  
  168. exception selenium.common.exceptions.UnexpectedAlertPresentException(msg=None, screen=None, stacktrace=None, alert_text=None)
  169. Bases: selenium.common.exceptions.WebDriverException
  170.  
  171. Thrown when an unexpected alert is appeared.
  172.  
  173. Usually raised when when an expected modal is blocking webdriver form executing any more commands.
  174.  
  175. exception selenium.common.exceptions.UnexpectedTagNameException(msg=None, screen=None, stacktrace=None)
  176. Bases: selenium.common.exceptions.WebDriverException
  177.  
  178. Thrown when a support class did not get an expected web element.
  179.  
  180. exception selenium.common.exceptions.WebDriverException(msg=None, screen=None, stacktrace=None)
  181. Bases: exceptions.Exception
  182.  
  183. Base webdriver exception.
  184.  
  185. 7.2. Action Chains
  186. The ActionChains implementation,
  187.  
  188. class selenium.webdriver.common.action_chains.ActionChains(driver)
  189. Bases: object
  190.  
  191. ActionChains are a way to automate low level interactions such as mouse movements, mouse button actions, key press, and context menu interactions. This is useful for doing more complex actions like hover over and drag and drop.
  192.  
  193. Generate user actions.
  194. When you call methods for actions on the ActionChains object, the actions are stored in a queue in the ActionChains object. When you call perform(), the events are fired in the order they are queued up.
  195. ActionChains can be used in a chain pattern:
  196.  
  197. menu = driver.find_element_by_css_selector(".nav")
  198. hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1")
  199.  
  200. ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()
  201. Or actions can be queued up one by one, then performed.:
  202.  
  203. menu = driver.find_element_by_css_selector(".nav")
  204. hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1")
  205.  
  206. actions = ActionChains(driver)
  207. actions.move_to_element(menu)
  208. actions.click(hidden_submenu)
  209. actions.perform()
  210. Either way, the actions are performed in the order they are called, one after another.
  211.  
  212. click(on_element=None)
  213. Clicks an element.
  214.  
  215. Args:
  216. on_element: The element to click. If None, clicks on current mouse position.
  217. click_and_hold(on_element=None)
  218. Holds down the left mouse button on an element.
  219.  
  220. Args:
  221. on_element: The element to mouse down. If None, clicks on current mouse position.
  222. context_click(on_element=None)
  223. Performs a context-click (right click) on an element.
  224.  
  225. Args:
  226. on_element: The element to context-click. If None, clicks on current mouse position.
  227. double_click(on_element=None)
  228. Double-clicks an element.
  229.  
  230. Args:
  231. on_element: The element to double-click. If None, clicks on current mouse position.
  232. drag_and_drop(source, target)
  233. Holds down the left mouse button on the source element,
  234. then moves to the target element and releases the mouse button.
  235. Args:
  236. source: The element to mouse down.
  237. target: The element to mouse up.
  238. drag_and_drop_by_offset(source, xoffset, yoffset)
  239. Holds down the left mouse button on the source element,
  240. then moves to the target offset and releases the mouse button.
  241. Args:
  242. source: The element to mouse down.
  243. xoffset: X offset to move to.
  244. yoffset: Y offset to move to.
  245. key_down(value, element=None)
  246. Sends a key press only, without releasing it.
  247. Should only be used with modifier keys (Control, Alt and Shift).
  248. Args:
  249. value: The modifier key to send. Values are defined in Keys class.
  250. element: The element to send keys. If None, sends a key to current focused element.
  251. Example, pressing ctrl+c:
  252.  
  253. ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()
  254. key_up(value, element=None)
  255. Releases a modifier key.
  256.  
  257. Args:
  258. value: The modifier key to send. Values are defined in Keys class.
  259. element: The element to send keys. If None, sends a key to current focused element.
  260. Example, pressing ctrl+c:
  261.  
  262. ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()
  263. move_by_offset(xoffset, yoffset)
  264. Moving the mouse to an offset from current mouse position.
  265.  
  266. Args:
  267. xoffset: X offset to move to, as a positive or negative integer.
  268. yoffset: Y offset to move to, as a positive or negative integer.
  269. move_to_element(to_element)
  270. Moving the mouse to the middle of an element.
  271.  
  272. Args:
  273. to_element: The WebElement to move to.
  274. move_to_element_with_offset(to_element, xoffset, yoffset)
  275. Move the mouse by an offset of the specified element.
  276. Offsets are relative to the top-left corner of the element.
  277. Args:
  278. to_element: The WebElement to move to.
  279. xoffset: X offset to move to.
  280. yoffset: Y offset to move to.
  281. perform()
  282. Performs all stored actions.
  283.  
  284. release(on_element=None)
  285. Releasing a held mouse button on an element.
  286.  
  287. Args:
  288. on_element: The element to mouse up. If None, releases on current mouse position.
  289. send_keys(*keys_to_send)
  290. Sends keys to current focused element.
  291.  
  292. Args:
  293. keys_to_send: The keys to send. Modifier keys constants can be found in the
  294. ‘Keys’ class.
  295.  
  296. send_keys_to_element(element, *keys_to_send)
  297. Sends keys to an element.
  298.  
  299. Args:
  300. element: The element to send keys.
  301. keys_to_send: The keys to send. Modifier keys constants can be found in the
  302. ‘Keys’ class.
  303.  
  304. 7.3. Alerts
  305. The Alert implementation.
  306.  
  307. class selenium.webdriver.common.alert.Alert(driver)
  308. Bases: object
  309.  
  310. Allows to work with alerts.
  311.  
  312. Use this class to interact with alert prompts. It contains methods for dismissing, accepting, inputting, and getting text from alert prompts.
  313.  
  314. Accepting / Dismissing alert prompts:
  315.  
  316. Alert(driver).accept()
  317. Alert(driver).dismiss()
  318. Inputting a value into an alert prompt:
  319.  
  320. name_prompt = Alert(driver) name_prompt.send_keys(“Willian Shakesphere”) name_prompt.accept()
  321. Reading a the text of a prompt for verification:
  322.  
  323. alert_text = Alert(driver).text self.assertEqual(“Do you wish to quit?”, alert_text)
  324. accept()
  325. Accepts the alert available.
  326.  
  327. Usage:: Alert(driver).accept() # Confirm a alert dialog.
  328.  
  329. authenticate(username, password)
  330. Send the username / password to an Authenticated dialog (like with Basic HTTP Auth). Implicitly ‘clicks ok’
  331.  
  332. Usage:: driver.switch_to.alert.authenticate(‘cheese’, ‘secretGouda’)
  333.  
  334. Args: -username: string to be set in the username section of the dialog -password: string to be set in the password section of the dialog
  335. dismiss()
  336. Dismisses the alert available.
  337.  
  338. send_keys(keysToSend)
  339. Send Keys to the Alert.
  340.  
  341. Args:
  342. keysToSend: The text to be sent to Alert.
  343. text
  344. Gets the text of the Alert.
  345.  
  346. 7.4. Special Keys
  347. The Keys implementation.
  348.  
  349. class selenium.webdriver.common.keys.Keys
  350. Bases: object
  351.  
  352. Set of special keys codes.
  353.  
  354. ADD = u'\ue025'
  355. ALT = u'\ue00a'
  356. ARROW_DOWN = u'\ue015'
  357. ARROW_LEFT = u'\ue012'
  358. ARROW_RIGHT = u'\ue014'
  359. ARROW_UP = u'\ue013'
  360. BACKSPACE = u'\ue003'
  361. BACK_SPACE = u'\ue003'
  362. CANCEL = u'\ue001'
  363. CLEAR = u'\ue005'
  364. COMMAND = u'\ue03d'
  365. CONTROL = u'\ue009'
  366. DECIMAL = u'\ue028'
  367. DELETE = u'\ue017'
  368. DIVIDE = u'\ue029'
  369. DOWN = u'\ue015'
  370. END = u'\ue010'
  371. ENTER = u'\ue007'
  372. EQUALS = u'\ue019'
  373. ESCAPE = u'\ue00c'
  374. F1 = u'\ue031'
  375. F10 = u'\ue03a'
  376. F11 = u'\ue03b'
  377. F12 = u'\ue03c'
  378. F2 = u'\ue032'
  379. F3 = u'\ue033'
  380. F4 = u'\ue034'
  381. F5 = u'\ue035'
  382. F6 = u'\ue036'
  383. F7 = u'\ue037'
  384. F8 = u'\ue038'
  385. F9 = u'\ue039'
  386. HELP = u'\ue002'
  387. HOME = u'\ue011'
  388. INSERT = u'\ue016'
  389. LEFT = u'\ue012'
  390. LEFT_ALT = u'\ue00a'
  391. LEFT_CONTROL = u'\ue009'
  392. LEFT_SHIFT = u'\ue008'
  393. META = u'\ue03d'
  394. MULTIPLY = u'\ue024'
  395. NULL = u'\ue000'
  396. NUMPAD0 = u'\ue01a'
  397. NUMPAD1 = u'\ue01b'
  398. NUMPAD2 = u'\ue01c'
  399. NUMPAD3 = u'\ue01d'
  400. NUMPAD4 = u'\ue01e'
  401. NUMPAD5 = u'\ue01f'
  402. NUMPAD6 = u'\ue020'
  403. NUMPAD7 = u'\ue021'
  404. NUMPAD8 = u'\ue022'
  405. NUMPAD9 = u'\ue023'
  406. PAGE_DOWN = u'\ue00f'
  407. PAGE_UP = u'\ue00e'
  408. PAUSE = u'\ue00b'
  409. RETURN = u'\ue006'
  410. RIGHT = u'\ue014'
  411. SEMICOLON = u'\ue018'
  412. SEPARATOR = u'\ue026'
  413. SHIFT = u'\ue008'
  414. SPACE = u'\ue00d'
  415. SUBTRACT = u'\ue027'
  416. TAB = u'\ue004'
  417. UP = u'\ue013'
  418. 7.5. Locate elements By
  419. These are the attributes which can be used to locate elements. See the Locating Elements chapter for example usages.
  420.  
  421. The By implementation.
  422.  
  423. class selenium.webdriver.common.by.By
  424. Bases: object
  425.  
  426. Set of supported locator strategies.
  427.  
  428. CLASS_NAME = 'class name'
  429. CSS_SELECTOR = 'css selector'
  430. ID = 'id'
  431. LINK_TEXT = 'link text'
  432. NAME = 'name'
  433. PARTIAL_LINK_TEXT = 'partial link text'
  434. TAG_NAME = 'tag name'
  435. XPATH = 'xpath'
  436. 7.6. Desired Capabilities
  437. See the Using Selenium with remote WebDriver section for example usages of desired capabilities.
  438.  
  439. The Desired Capabilities implementation.
  440.  
  441. class selenium.webdriver.common.desired_capabilities.DesiredCapabilities
  442. Bases: object
  443.  
  444. Set of default supported desired capabilities.
  445.  
  446. Use this as a starting point for creating a desired capabilities object for requesting remote webdrivers for connecting to selenium server or selenium grid.
  447.  
  448. Usage Example:
  449.  
  450. from selenium import webdriver
  451.  
  452. selenium_grid_url = “http://198.0.0.1:4444/wd/hub“
  453.  
  454. # Create a desired capabilities object as a starting point. capabilities = DesiredCapabilities.FIREFOX.copy() capabilities[‘platform’] = “WINDOWS” capabilities[‘version’] = “10”
  455.  
  456. # Instantiate an instance of Remote WebDriver with the desired capabilities. driver = webdriver.Remote(desired_capabilities=capabilities,
  457.  
  458. command_executor=selenium_grid_url)
  459. Note: Always use ‘.copy()’ on the DesiredCapabilities object to avoid the side effects of altering the Global class instance.
  460.  
  461. ANDROID = {'platform': 'ANDROID', 'browserName': 'android', 'version': '', 'javascriptEnabled': True}
  462. CHROME = {'platform': 'ANY', 'browserName': 'chrome', 'version': '', 'javascriptEnabled': True}
  463. EDGE = {'platform': 'WINDOWS', 'browserName': 'MicrosoftEdge', 'version': ''}
  464. FIREFOX = {'platform': 'ANY', 'browserName': 'firefox', 'version': '', 'marionette': False, 'javascriptEnabled': True}
  465. HTMLUNIT = {'platform': 'ANY', 'browserName': 'htmlunit', 'version': ''}
  466. HTMLUNITWITHJS = {'platform': 'ANY', 'browserName': 'htmlunit', 'version': 'firefox', 'javascriptEnabled': True}
  467. INTERNETEXPLORER = {'platform': 'WINDOWS', 'browserName': 'internet explorer', 'version': '', 'javascriptEnabled': True}
  468. IPAD = {'platform': 'MAC', 'browserName': 'iPad', 'version': '', 'javascriptEnabled': True}
  469. IPHONE = {'platform': 'MAC', 'browserName': 'iPhone', 'version': '', 'javascriptEnabled': True}
  470. OPERA = {'platform': 'ANY', 'browserName': 'opera', 'version': '', 'javascriptEnabled': True}
  471. PHANTOMJS = {'platform': 'ANY', 'browserName': 'phantomjs', 'version': '', 'javascriptEnabled': True}
  472. SAFARI = {'platform': 'MAC', 'browserName': 'safari', 'version': '', 'javascriptEnabled': True}
  473. 7.7. Utilities
  474. The Utils methods.
  475.  
  476. selenium.webdriver.common.utils.find_connectable_ip(host, port=None)
  477. Resolve a hostname to an IP, preferring IPv4 addresses.
  478.  
  479. We prefer IPv4 so that we don’t change behavior from previous IPv4-only implementations, and because some drivers (e.g., FirefoxDriver) do not support IPv6 connections.
  480.  
  481. If the optional port number is provided, only IPs that listen on the given port are considered.
  482.  
  483. Args:
  484. host - A hostname.
  485. port - Optional port number.
  486. Returns:
  487. A single IP address, as a string. If any IPv4 address is found, one is returned. Otherwise, if any IPv6 address is found, one is returned. If neither, then None is returned.
  488.  
  489. selenium.webdriver.common.utils.free_port()
  490. Determines a free port using sockets.
  491.  
  492. selenium.webdriver.common.utils.is_connectable(port, host='localhost')
  493. Tries to connect to the server at port to see if it is running.
  494.  
  495. Args:
  496. port: The port to connect.
  497. selenium.webdriver.common.utils.is_url_connectable(port)
  498. Tries to connect to the HTTP server at /status path and specified port to see if it responds successfully.
  499.  
  500. Args:
  501. port: The port to connect.
  502. selenium.webdriver.common.utils.join_host_port(host, port)
  503. Joins a hostname and port together.
  504.  
  505. This is a minimal implementation intended to cope with IPv6 literals. For example, _join_host_port(‘::1’, 80) == ‘[::1]:80’.
  506.  
  507. Args:
  508. host - A hostname.
  509. port - An integer port.
  510. selenium.webdriver.common.utils.keys_to_typing(value)
  511. Processes the values that will be typed in the element.
  512.  
  513. 7.8. Firefox WebDriver
  514. class selenium.webdriver.firefox.webdriver.WebDriver(firefox_profile=None, firefox_binary=None, timeout=30, capabilities=None, proxy=None, executable_path='wires', firefox_options=None)
  515. Bases: selenium.webdriver.remote.webdriver.WebDriver
  516.  
  517. quit()
  518. Quits the driver and close every associated window.
  519.  
  520. set_context(context)
  521. NATIVE_EVENTS_ALLOWED = True
  522. firefox_profile
  523. 7.9. Chrome WebDriver
  524. class selenium.webdriver.chrome.webdriver.WebDriver(executable_path='chromedriver', port=0, chrome_options=None, service_args=None, desired_capabilities=None, service_log_path=None)
  525. Bases: selenium.webdriver.remote.webdriver.WebDriver
  526.  
  527. Controls the ChromeDriver and allows you to drive the browser.
  528.  
  529. You will need to download the ChromeDriver executable from http://chromedriver.storage.googleapis.com/index.html
  530.  
  531. create_options()
  532. launch_app(id)
  533. Launches Chrome app specified by id.
  534.  
  535. quit()
  536. Closes the browser and shuts down the ChromeDriver executable that is started when starting the ChromeDriver
  537.  
  538. 7.10. Remote WebDriver
  539. The WebDriver implementation.
  540.  
  541. class selenium.webdriver.remote.webdriver.WebDriver(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=None, browser_profile=None, proxy=None, keep_alive=False, file_detector=None)
  542. Bases: object
  543.  
  544. Controls a browser by sending commands to a remote server. This server is expected to be running the WebDriver wire protocol as defined at https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
  545.  
  546. Attributes:
  547. session_id - String ID of the browser session started and controlled by this WebDriver.
  548.  
  549. capabilities - Dictionaty of effective capabilities of this browser session as returned
  550. by the remote server. See https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
  551.  
  552. command_executor - remote_connection.RemoteConnection object used to execute commands.
  553.  
  554. error_handler - errorhandler.ErrorHandler object used to handle errors.
  555.  
  556. add_cookie(cookie_dict)
  557. Adds a cookie to your current session.
  558.  
  559. Args:
  560. cookie_dict: A dictionary object, with required keys - “name” and “value”;
  561. optional keys - “path”, “domain”, “secure”, “expiry”
  562.  
  563. Usage:
  564. driver.add_cookie({‘name’ : ‘foo’, ‘value’ : ‘bar’}) driver.add_cookie({‘name’ : ‘foo’, ‘value’ : ‘bar’, ‘path’ : ‘/’}) driver.add_cookie({‘name’ : ‘foo’, ‘value’ : ‘bar’, ‘path’ : ‘/’, ‘secure’:True})
  565. back()
  566. Goes one step backward in the browser history.
  567.  
  568. Usage: driver.back()
  569. close()
  570. Closes the current window.
  571.  
  572. Usage: driver.close()
  573. create_web_element(element_id)
  574. Creates a web element with the specified element_id.
  575.  
  576. delete_all_cookies()
  577. Delete all cookies in the scope of the session.
  578.  
  579. Usage: driver.delete_all_cookies()
  580. delete_cookie(name)
  581. Deletes a single cookie with the given name.
  582.  
  583. Usage: driver.delete_cookie(‘my_cookie’)
  584. execute(driver_command, params=None)
  585. Sends a command to be executed by a command.CommandExecutor.
  586.  
  587. Args:
  588. driver_command: The name of the command to execute as a string.
  589. params: A dictionary of named parameters to send with the command.
  590. Returns:
  591. The command’s JSON response loaded into a dictionary object.
  592.  
  593. execute_async_script(script, *args)
  594. Asynchronously Executes JavaScript in the current window/frame.
  595.  
  596. Args:
  597. script: The JavaScript to execute.
  598. *args: Any applicable arguments for your JavaScript.
  599. Usage:
  600. driver.execute_async_script(‘document.title’)
  601.  
  602. execute_script(script, *args)
  603. Synchronously Executes JavaScript in the current window/frame.
  604.  
  605. Args:
  606. script: The JavaScript to execute.
  607. *args: Any applicable arguments for your JavaScript.
  608. Usage:
  609. driver.execute_script(‘document.title’)
  610.  
  611. file_detector_context(*args, **kwds)
  612. Overrides the current file detector (if necessary) in limited context. Ensures the original file detector is set afterwards.
  613.  
  614. Example:
  615.  
  616. with webdriver.file_detector_context(UselessFileDetector):
  617. someinput.send_keys(‘/etc/hosts’)
  618. Args:
  619. file_detector_class - Class of the desired file detector. If the class is different
  620. from the current file_detector, then the class is instantiated with args and kwargs and used as a file detector during the duration of the context manager.
  621.  
  622. args - Optional arguments that get passed to the file detector class during
  623. instantiation.
  624.  
  625. kwargs - Keyword arguments, passed the same way as args.
  626.  
  627. find_element(by='id', value=None)
  628. ‘Private’ method used by the find_element_by_* methods.
  629.  
  630. Usage: Use the corresponding find_element_by_* instead of this.
  631. Return type: WebElement
  632. find_element_by_class_name(name)
  633. Finds an element by class name.
  634.  
  635. Args:
  636. name: The class name of the element to find.
  637. Usage:
  638. driver.find_element_by_class_name(‘foo’)
  639.  
  640. find_element_by_css_selector(css_selector)
  641. Finds an element by css selector.
  642.  
  643. Args:
  644. css_selector: The css selector to use when finding elements.
  645. Usage:
  646. driver.find_element_by_css_selector(‘#foo’)
  647.  
  648. find_element_by_id(id_)
  649. Finds an element by id.
  650.  
  651. Args:
  652. id_ - The id of the element to be found.
  653. Usage:
  654. driver.find_element_by_id(‘foo’)
  655.  
  656. find_element_by_link_text(link_text)
  657. Finds an element by link text.
  658.  
  659. Args:
  660. link_text: The text of the element to be found.
  661. Usage:
  662. driver.find_element_by_link_text(‘Sign In’)
  663.  
  664. find_element_by_name(name)
  665. Finds an element by name.
  666.  
  667. Args:
  668. name: The name of the element to find.
  669. Usage:
  670. driver.find_element_by_name(‘foo’)
  671.  
  672. find_element_by_partial_link_text(link_text)
  673. Finds an element by a partial match of its link text.
  674.  
  675. Args:
  676. link_text: The text of the element to partially match on.
  677. Usage:
  678. driver.find_element_by_partial_link_text(‘Sign’)
  679.  
  680. find_element_by_tag_name(name)
  681. Finds an element by tag name.
  682.  
  683. Args:
  684. name: The tag name of the element to find.
  685. Usage:
  686. driver.find_element_by_tag_name(‘foo’)
  687.  
  688. find_element_by_xpath(xpath)
  689. Finds an element by xpath.
  690.  
  691. Args:
  692. xpath - The xpath locator of the element to find.
  693. Usage:
  694. driver.find_element_by_xpath(‘//div/td[1]’)
  695.  
  696. find_elements(by='id', value=None)
  697. ‘Private’ method used by the find_elements_by_* methods.
  698.  
  699. Usage: Use the corresponding find_elements_by_* instead of this.
  700. Return type: list of WebElement
  701. find_elements_by_class_name(name)
  702. Finds elements by class name.
  703.  
  704. Args:
  705. name: The class name of the elements to find.
  706. Usage:
  707. driver.find_elements_by_class_name(‘foo’)
  708.  
  709. find_elements_by_css_selector(css_selector)
  710. Finds elements by css selector.
  711.  
  712. Args:
  713. css_selector: The css selector to use when finding elements.
  714. Usage:
  715. driver.find_elements_by_css_selector(‘.foo’)
  716.  
  717. find_elements_by_id(id_)
  718. Finds multiple elements by id.
  719.  
  720. Args:
  721. id_ - The id of the elements to be found.
  722. Usage:
  723. driver.find_elements_by_id(‘foo’)
  724.  
  725. find_elements_by_link_text(text)
  726. Finds elements by link text.
  727.  
  728. Args:
  729. link_text: The text of the elements to be found.
  730. Usage:
  731. driver.find_elements_by_link_text(‘Sign In’)
  732.  
  733. find_elements_by_name(name)
  734. Finds elements by name.
  735.  
  736. Args:
  737. name: The name of the elements to find.
  738. Usage:
  739. driver.find_elements_by_name(‘foo’)
  740.  
  741. find_elements_by_partial_link_text(link_text)
  742. Finds elements by a partial match of their link text.
  743.  
  744. Args:
  745. link_text: The text of the element to partial match on.
  746. Usage:
  747. driver.find_element_by_partial_link_text(‘Sign’)
  748.  
  749. find_elements_by_tag_name(name)
  750. Finds elements by tag name.
  751.  
  752. Args:
  753. name: The tag name the use when finding elements.
  754. Usage:
  755. driver.find_elements_by_tag_name(‘foo’)
  756.  
  757. find_elements_by_xpath(xpath)
  758. Finds multiple elements by xpath.
  759.  
  760. Args:
  761. xpath - The xpath locator of the elements to be found.
  762. Usage:
  763. driver.find_elements_by_xpath(“//div[contains(@class, ‘foo’)]”)
  764.  
  765. forward()
  766. Goes one step forward in the browser history.
  767.  
  768. Usage: driver.forward()
  769. get(url)
  770. Loads a web page in the current browser session.
  771.  
  772. get_cookie(name)
  773. Get a single cookie by name. Returns the cookie if found, None if not.
  774.  
  775. Usage: driver.get_cookie(‘my_cookie’)
  776. get_cookies()
  777. Returns a set of dictionaries, corresponding to cookies visible in the current session.
  778.  
  779. Usage: driver.get_cookies()
  780. get_log(log_type)
  781. Gets the log for a given log type
  782.  
  783. Args:
  784. log_type: type of log that which will be returned
  785. Usage:
  786. driver.get_log(‘browser’) driver.get_log(‘driver’) driver.get_log(‘client’) driver.get_log(‘server’)
  787.  
  788. get_screenshot_as_base64()
  789. Gets the screenshot of the current window as a base64 encoded string
  790. which is useful in embedded images in HTML.
  791. Usage: driver.get_screenshot_as_base64()
  792. get_screenshot_as_file(filename)
  793. Gets the screenshot of the current window. Returns False if there is
  794. any IOError, else returns True. Use full paths in your filename.
  795. Args:
  796. filename: The full path you wish to save your screenshot to.
  797. Usage:
  798. driver.get_screenshot_as_file(‘/Screenshots/foo.png’)
  799.  
  800. get_screenshot_as_png()
  801. Gets the screenshot of the current window as a binary data.
  802.  
  803. Usage: driver.get_screenshot_as_png()
  804. get_window_position(windowHandle='current')
  805. Gets the x,y position of the current window.
  806.  
  807. Usage: driver.get_window_position()
  808. get_window_size(windowHandle='current')
  809. Gets the width and height of the current window.
  810.  
  811. Usage: driver.get_window_size()
  812. implicitly_wait(time_to_wait)
  813. Sets a sticky timeout to implicitly wait for an element to be found,
  814. or a command to complete. This method only needs to be called one time per session. To set the timeout for calls to execute_async_script, see set_script_timeout.
  815. Args:
  816. time_to_wait: Amount of time to wait (in seconds)
  817. Usage:
  818. driver.implicitly_wait(30)
  819.  
  820. maximize_window()
  821. Maximizes the current window that webdriver is using
  822.  
  823. quit()
  824. Quits the driver and closes every associated window.
  825.  
  826. Usage: driver.quit()
  827. refresh()
  828. Refreshes the current page.
  829.  
  830. Usage: driver.refresh()
  831. save_screenshot(filename)
  832. Gets the screenshot of the current window. Returns False if there is
  833. any IOError, else returns True. Use full paths in your filename.
  834. Args:
  835. filename: The full path you wish to save your screenshot to.
  836. Usage:
  837. driver.get_screenshot_as_file(‘/Screenshots/foo.png’)
  838.  
  839. set_page_load_timeout(time_to_wait)
  840. Set the amount of time to wait for a page load to complete
  841. before throwing an error.
  842. Args:
  843. time_to_wait: The amount of time to wait
  844. Usage:
  845. driver.set_page_load_timeout(30)
  846.  
  847. set_script_timeout(time_to_wait)
  848. Set the amount of time that the script should wait during an
  849. execute_async_script call before throwing an error.
  850. Args:
  851. time_to_wait: The amount of time to wait (in seconds)
  852. Usage:
  853. driver.set_script_timeout(30)
  854.  
  855. set_window_position(x, y, windowHandle='current')
  856. Sets the x,y position of the current window. (window.moveTo)
  857.  
  858. Args:
  859. x: the x-coordinate in pixels to set the window position
  860. y: the y-coordinate in pixels to set the window position
  861. Usage:
  862. driver.set_window_position(0,0)
  863.  
  864. set_window_size(width, height, windowHandle='current')
  865. Sets the width and height of the current window. (window.resizeTo)
  866.  
  867. Args:
  868. width: the width in pixels to set the window to
  869. height: the height in pixels to set the window to
  870. Usage:
  871. driver.set_window_size(800,600)
  872.  
  873. start_client()
  874. Called before starting a new session. This method may be overridden to define custom startup behavior.
  875.  
  876. start_session(desired_capabilities, browser_profile=None)
  877. Creates a new session with the desired capabilities.
  878.  
  879. Args:
  880. browser_name - The name of the browser to request.
  881. version - Which browser version to request.
  882. platform - Which platform to request the browser on.
  883. javascript_enabled - Whether the new session should support JavaScript.
  884. browser_profile - A selenium.webdriver.firefox.firefox_profile.FirefoxProfile object. Only used if Firefox is requested.
  885. stop_client()
  886. Called after executing a quit command. This method may be overridden to define custom shutdown behavior.
  887.  
  888. switch_to_active_element()
  889. Deprecated use driver.switch_to.active_element
  890.  
  891. switch_to_alert()
  892. Deprecated use driver.switch_to.alert
  893.  
  894. switch_to_default_content()
  895. Deprecated use driver.switch_to.default_content
  896.  
  897. switch_to_frame(frame_reference)
  898. Deprecated use driver.switch_to.frame
  899.  
  900. switch_to_window(window_name)
  901. Deprecated use driver.switch_to.window
  902.  
  903. application_cache
  904. Returns a ApplicationCache Object to interact with the browser app cache
  905.  
  906. current_url
  907. Gets the URL of the current page.
  908.  
  909. Usage: driver.current_url
  910. current_window_handle
  911. Returns the handle of the current window.
  912.  
  913. Usage: driver.current_window_handle
  914. desired_capabilities
  915. returns the drivers current desired capabilities being used
  916.  
  917. file_detector
  918. log_types
  919. Gets a list of the available log types
  920.  
  921. Usage: driver.log_types
  922. mobile
  923. name
  924. Returns the name of the underlying browser for this instance.
  925.  
  926. Usage:
  927. driver.name
  928. orientation
  929. Gets the current orientation of the device
  930.  
  931. Usage: orientation = driver.orientation
  932. page_source
  933. Gets the source of the current page.
  934.  
  935. Usage: driver.page_source
  936. switch_to
  937. title
  938. Returns the title of the current page.
  939.  
  940. Usage: driver.title
  941. window_handles
  942. Returns the handles of all windows within the current session.
  943.  
  944. Usage: driver.window_handles
  945. 7.11. WebElement
  946. class selenium.webdriver.remote.webelement.WebElement(parent, id_, w3c=False)
  947. Bases: object
  948.  
  949. Represents a DOM element.
  950.  
  951. Generally, all interesting operations that interact with a document will be performed through this interface.
  952.  
  953. All method calls will do a freshness check to ensure that the element reference is still valid. This essentially determines whether or not the element is still attached to the DOM. If this test fails, then an StaleElementReferenceException is thrown, and all future calls to this instance will fail.
  954.  
  955. clear()
  956. Clears the text if it’s a text entry element.
  957.  
  958. click()
  959. Clicks the element.
  960.  
  961. find_element(by='id', value=None)
  962. find_element_by_class_name(name)
  963. Finds element within this element’s children by class name.
  964.  
  965. Args:
  966. name - class name to search for.
  967. find_element_by_css_selector(css_selector)
  968. Finds element within this element’s children by CSS selector.
  969.  
  970. Args:
  971. css_selector - CSS selctor string, ex: ‘a.nav#home’
  972. find_element_by_id(id_)
  973. Finds element within this element’s children by ID.
  974.  
  975. Args:
  976. id_ - ID of child element to locate.
  977. find_element_by_link_text(link_text)
  978. Finds element within this element’s children by visible link text.
  979.  
  980. Args:
  981. link_text - Link text string to search for.
  982. find_element_by_name(name)
  983. Finds element within this element’s children by name.
  984.  
  985. Args:
  986. name - name property of the element to find.
  987. find_element_by_partial_link_text(link_text)
  988. Finds element within this element’s children by partially visible link text.
  989.  
  990. Args:
  991. link_text - Link text string to search for.
  992. find_element_by_tag_name(name)
  993. Finds element within this element’s children by tag name.
  994.  
  995. Args:
  996. name - name of html tag (eg: h1, a, span)
  997. find_element_by_xpath(xpath)
  998. Finds element by xpath.
  999.  
  1000. Args: xpath - xpath of element to locate. “//input[@class=’myelement’]”
  1001. Note: The base path will be relative to this element’s location.
  1002.  
  1003. This will select the first link under this element.
  1004.  
  1005. myelement.find_elements_by_xpath(".//a")
  1006. However, this will select the first link on the page.
  1007.  
  1008. myelement.find_elements_by_xpath("//a")
  1009. find_elements(by='id', value=None)
  1010. find_elements_by_class_name(name)
  1011. Finds a list of elements within this element’s children by class name.
  1012.  
  1013. Args:
  1014. name - class name to search for.
  1015. find_elements_by_css_selector(css_selector)
  1016. Finds a list of elements within this element’s children by CSS selector.
  1017.  
  1018. Args:
  1019. css_selector - CSS selctor string, ex: ‘a.nav#home’
  1020. find_elements_by_id(id_)
  1021. Finds a list of elements within this element’s children by ID.
  1022.  
  1023. Args:
  1024. id_ - Id of child element to find.
  1025. find_elements_by_link_text(link_text)
  1026. Finds a list of elements within this element’s children by visible link text.
  1027.  
  1028. Args:
  1029. link_text - Link text string to search for.
  1030. find_elements_by_name(name)
  1031. Finds a list of elements within this element’s children by name.
  1032.  
  1033. Args:
  1034. name - name property to search for.
  1035. find_elements_by_partial_link_text(link_text)
  1036. Finds a list of elements within this element’s children by link text.
  1037.  
  1038. Args:
  1039. link_text - Link text string to search for.
  1040. find_elements_by_tag_name(name)
  1041. Finds a list of elements within this element’s children by tag name.
  1042.  
  1043. Args:
  1044. name - name of html tag (eg: h1, a, span)
  1045. find_elements_by_xpath(xpath)
  1046. Finds elements within the element by xpath.
  1047.  
  1048. Args:
  1049. xpath - xpath locator string.
  1050. Note: The base path will be relative to this element’s location.
  1051.  
  1052. This will select all links under this element.
  1053.  
  1054. myelement.find_elements_by_xpath(".//a")
  1055. However, this will select all links in the page itself.
  1056.  
  1057. myelement.find_elements_by_xpath("//a")
  1058. get_attribute(name)
  1059. Gets the given attribute or property of the element.
  1060.  
  1061. This method will first try to return the value of a property with the given name. If a property with that name doesn’t exist, it returns the value of the attribute with the same name. If there’s no attribute with that name, None is returned.
  1062.  
  1063. Values which are considered truthy, that is equals “true” or “false”, are returned as booleans. All other non-None values are returned as strings. For attributes or properties which do not exist, None is returned.
  1064.  
  1065. Args:
  1066. name - Name of the attribute/property to retrieve.
  1067. Example:
  1068.  
  1069. # Check if the "active" CSS class is applied to an element.
  1070. is_active = "active" in target_element.get_attribute("class")
  1071. is_displayed()
  1072. Whether the element is visible to a user.
  1073.  
  1074. is_enabled()
  1075. Returns whether the element is enabled.
  1076.  
  1077. is_selected()
  1078. Returns whether the element is selected.
  1079.  
  1080. Can be used to check if a checkbox or radio button is selected.
  1081.  
  1082. screenshot(filename)
  1083. Gets the screenshot of the current element. Returns False if there is
  1084. any IOError, else returns True. Use full paths in your filename.
  1085. Args:
  1086. filename: The full path you wish to save your screenshot to.
  1087. Usage:
  1088. element.screenshot(‘/Screenshots/foo.png’)
  1089.  
  1090. send_keys(*value)
  1091. Simulates typing into the element.
  1092.  
  1093. Args:
  1094. value - A string for typing, or setting form fields. For setting
  1095. file inputs, this could be a local file path.
  1096.  
  1097. Use this to send simple key events or to fill out form fields:
  1098.  
  1099. form_textfield = driver.find_element_by_name('username')
  1100. form_textfield.send_keys("admin")
  1101. This can also be used to set file inputs.
  1102.  
  1103. file_input = driver.find_element_by_name('profilePic')
  1104. file_input.send_keys("path/to/profilepic.gif")
  1105. # Generally it's better to wrap the file path in one of the methods
  1106. # in os.path to return the actual path to support cross OS testing.
  1107. # file_input.send_keys(os.path.abspath("path/to/profilepic.gif"))
  1108. submit()
  1109. Submits a form.
  1110.  
  1111. value_of_css_property(property_name)
  1112. The value of a CSS property.
  1113.  
  1114. id
  1115. Internal ID used by selenium.
  1116.  
  1117. This is mainly for internal use. Simple use cases such as checking if 2 webelements refer to the same element, can be done using ==:
  1118.  
  1119. if element1 == element2:
  1120. print("These 2 are equal")
  1121. location
  1122. The location of the element in the renderable canvas.
  1123.  
  1124. location_once_scrolled_into_view
  1125. THIS PROPERTY MAY CHANGE WITHOUT WARNING. Use this to discover where on the screen an element is so that we can click it. This method should cause the element to be scrolled into view.
  1126.  
  1127. Returns the top lefthand corner location on the screen, or None if the element is not visible.
  1128.  
  1129. parent
  1130. Internal reference to the WebDriver instance this element was found from.
  1131.  
  1132. rect
  1133. A dictionary with the size and location of the element.
  1134.  
  1135. screenshot_as_base64
  1136. Gets the screenshot of the current element as a base64 encoded string.
  1137.  
  1138. Usage: img_b64 = element.screenshot_as_base64
  1139. screenshot_as_png
  1140. Gets the screenshot of the current element as a binary data.
  1141.  
  1142. Usage: element_png = element.screenshot_as_png
  1143. size
  1144. The size of the element.
  1145.  
  1146. tag_name
  1147. This element’s tagName property.
  1148.  
  1149. text
  1150. The text of the element.
  1151.  
  1152. 7.12. UI Support
  1153. class selenium.webdriver.support.select.Select(webelement)
  1154. deselect_all()
  1155. Clear all selected entries. This is only valid when the SELECT supports multiple selections. throws NotImplementedError If the SELECT does not support multiple selections
  1156.  
  1157. deselect_by_index(index)
  1158. Deselect the option at the given index. This is done by examing the “index” attribute of an element, and not merely by counting.
  1159.  
  1160. Args:
  1161. index - The option at this index will be deselected
  1162. throws NoSuchElementException If there is no option with specisied index in SELECT
  1163.  
  1164. deselect_by_value(value)
  1165. Deselect all options that have a value matching the argument. That is, when given “foo” this would deselect an option like:
  1166.  
  1167. <option value=”foo”>Bar</option>
  1168. Args:
  1169. value - The value to match against
  1170. throws NoSuchElementException If there is no option with specisied value in SELECT
  1171.  
  1172. deselect_by_visible_text(text)
  1173. Deselect all options that display text matching the argument. That is, when given “Bar” this would deselect an option like:
  1174.  
  1175. <option value=”foo”>Bar</option>
  1176.  
  1177. Args:
  1178. text - The visible text to match against
  1179. select_by_index(index)
  1180. Select the option at the given index. This is done by examing the “index” attribute of an element, and not merely by counting.
  1181.  
  1182. Args:
  1183. index - The option at this index will be selected
  1184. throws NoSuchElementException If there is no option with specisied index in SELECT
  1185.  
  1186. select_by_value(value)
  1187. Select all options that have a value matching the argument. That is, when given “foo” this would select an option like:
  1188.  
  1189. <option value=”foo”>Bar</option>
  1190.  
  1191. Args:
  1192. value - The value to match against
  1193. throws NoSuchElementException If there is no option with specisied value in SELECT
  1194.  
  1195. select_by_visible_text(text)
  1196. Select all options that display text matching the argument. That is, when given “Bar” this would select an option like:
  1197.  
  1198. <option value=”foo”>Bar</option>
  1199. Args:
  1200. text - The visible text to match against
  1201. throws NoSuchElementException If there is no option with specisied text in SELECT
  1202.  
  1203. all_selected_options
  1204. Returns a list of all selected options belonging to this select tag
  1205.  
  1206. first_selected_option
  1207. The first selected option in this select tag (or the currently selected option in a normal select)
  1208.  
  1209. options
  1210. Returns a list of all options belonging to this select tag
  1211.  
  1212. class selenium.webdriver.support.wait.WebDriverWait(driver, timeout, poll_frequency=0.5, ignored_exceptions=None)
  1213. Bases: object
  1214.  
  1215. until(method, message='')
  1216. Calls the method provided with the driver as an argument until the return value is not False.
  1217.  
  1218. until_not(method, message='')
  1219. Calls the method provided with the driver as an argument until the return value is False.
  1220.  
  1221. 7.13. Color Support
  1222. class selenium.webdriver.support.color.Color(red, green, blue, alpha=1)
  1223. Bases: object
  1224.  
  1225. Color conversion support class
  1226.  
  1227. Example:
  1228.  
  1229. from selenium.webdriver.support.color import Color
  1230.  
  1231. print(Color.from_string('#00ff33').rgba)
  1232. print(Color.from_string('rgb(1, 255, 3)').hex)
  1233. print(Color.from_string('blue').rgba)
  1234. static from_string(str_)
  1235. hex
  1236. rgb
  1237. rgba
  1238. 7.14. Expected conditions Support
  1239. class selenium.webdriver.support.expected_conditions.alert_is_present
  1240. Bases: object
  1241.  
  1242. Expect an alert to be present.
  1243.  
  1244. class selenium.webdriver.support.expected_conditions.element_located_selection_state_to_be(locator, is_selected)
  1245. Bases: object
  1246.  
  1247. An expectation to locate an element and check if the selection state specified is in that state. locator is a tuple of (by, path) is_selected is a boolean
  1248.  
  1249. class selenium.webdriver.support.expected_conditions.element_located_to_be_selected(locator)
  1250. Bases: object
  1251.  
  1252. An expectation for the element to be located is selected. locator is a tuple of (by, path)
  1253.  
  1254. class selenium.webdriver.support.expected_conditions.element_selection_state_to_be(element, is_selected)
  1255. Bases: object
  1256.  
  1257. An expectation for checking if the given element is selected. element is WebElement object is_selected is a Boolean.”
  1258.  
  1259. class selenium.webdriver.support.expected_conditions.element_to_be_clickable(locator)
  1260. Bases: object
  1261.  
  1262. An Expectation for checking an element is visible and enabled such that you can click it.
  1263.  
  1264. class selenium.webdriver.support.expected_conditions.element_to_be_selected(element)
  1265. Bases: object
  1266.  
  1267. An expectation for checking the selection is selected. element is WebElement object
  1268.  
  1269. class selenium.webdriver.support.expected_conditions.frame_to_be_available_and_switch_to_it(locator)
  1270. Bases: object
  1271.  
  1272. An expectation for checking whether the given frame is available to switch to. If the frame is available it switches the given driver to the specified frame.
  1273.  
  1274. class selenium.webdriver.support.expected_conditions.invisibility_of_element_located(locator)
  1275. Bases: object
  1276.  
  1277. An Expectation for checking that an element is either invisible or not present on the DOM.
  1278.  
  1279. locator used to find the element
  1280.  
  1281. class selenium.webdriver.support.expected_conditions.presence_of_all_elements_located(locator)
  1282. Bases: object
  1283.  
  1284. An expectation for checking that there is at least one element present on a web page. locator is used to find the element returns the list of WebElements once they are located
  1285.  
  1286. class selenium.webdriver.support.expected_conditions.presence_of_element_located(locator)
  1287. Bases: object
  1288.  
  1289. An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible. locator - used to find the element returns the WebElement once it is located
  1290.  
  1291. class selenium.webdriver.support.expected_conditions.staleness_of(element)
  1292. Bases: object
  1293.  
  1294. Wait until an element is no longer attached to the DOM. element is the element to wait for. returns False if the element is still attached to the DOM, true otherwise.
  1295.  
  1296. class selenium.webdriver.support.expected_conditions.text_to_be_present_in_element(locator, text_)
  1297. Bases: object
  1298.  
  1299. An expectation for checking if the given text is present in the specified element. locator, text
  1300.  
  1301. class selenium.webdriver.support.expected_conditions.text_to_be_present_in_element_value(locator, text_)
  1302. Bases: object
  1303.  
  1304. An expectation for checking if the given text is present in the element’s locator, text
  1305.  
  1306. class selenium.webdriver.support.expected_conditions.title_contains(title)
  1307. Bases: object
  1308.  
  1309. An expectation for checking that the title contains a case-sensitive substring. title is the fragment of title expected returns True when the title matches, False otherwise
  1310.  
  1311. class selenium.webdriver.support.expected_conditions.title_is(title)
  1312. Bases: object
  1313.  
  1314. An expectation for checking the title of a page. title is the expected title, which must be an exact match returns True if the title matches, false otherwise.
  1315.  
  1316. class selenium.webdriver.support.expected_conditions.visibility_of(element)
  1317. Bases: object
  1318.  
  1319. An expectation for checking that an element, known to be present on the DOM of a page, is visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0. element is the WebElement returns the (same) WebElement once it is visible
  1320.  
  1321. class selenium.webdriver.support.expected_conditions.visibility_of_any_elements_located(locator)
  1322. Bases: object
  1323.  
  1324. An expectation for checking that there is at least one element visible on a web page. locator is used to find the element returns the list of WebElements once they are located
  1325.  
  1326. class selenium.webdriver.support.expected_conditions.visibility_of_element_located(locator)
  1327. Bases: object
  1328.  
  1329. An expectation for checking that an element is present on the DOM of a page and visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0. locator - used to find the element returns the WebElement once it is located and
Add Comment
Please, Sign In to add comment