Python selenium webelement attributes

selenium.webdriver.remote.webelement¶

ABC’s will allow custom types to be registered as a WebElement to pass type checks.

class selenium.webdriver.remote.webelement. WebElement ( parent, id_ ) [source] ¶

Generally, all interesting operations that interact with a document will be performed through this interface.

All method calls will do a freshness check to ensure that the element reference is still valid. This essentially determines whether 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.

Returns the ARIA Level of the current webelement.

Returns the ARIA role of the current web element.

Clears the text if it’s a text entry element.

find_element ( by=’id’, value=None ) → selenium.webdriver.remote.webelement.WebElement [source] ¶

Find an element given a By strategy and locator.

element = element.find_element(By.ID, 'foo') 

Find elements given a By strategy and locator.

element = element.find_elements(By.CLASS_NAME, 'foo') 

Gets the given attribute or property of the element.

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.

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.

To obtain the exact value of the attribute or property, use get_dom_attribute() or get_property() methods respectively.

# Check if the "active" CSS class is applied to an element. is_active = "active" in target_element.get_attribute("class") 

Gets the given attribute of the element. Unlike get_attribute() , this method only returns attributes declared in the element’s HTML markup.

text_length = target_element.get_dom_attribute("class") 

Gets the given property of the element.

text_length = target_element.get_property("text_length") 

Internal ID used by selenium.

This is mainly for internal use. Simple use cases such as checking if 2 webelements refer to the same element, can be done using == :

if element1 == element2: print("These 2 are equal") 

Whether the element is visible to a user.

Returns whether the element is enabled.

Returns whether the element is selected.

Can be used to check if a checkbox or radio button is selected.

The location of the element in the renderable canvas.

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.

Returns the top lefthand corner location on the screen, or zero coordinates if the element is not visible.

Internal reference to the WebDriver instance this element was found from.

A dictionary with the size and location of the element.

screenshot ( filename ) → bool [source] ¶

Saves a screenshot of the current element to a PNG image file. Returns False if there is any IOError, else returns True. Use full paths in your filename.

  • filename: The full path you wish to save your screenshot to. This should end with a .png extension.
element.screenshot('/Screenshots/foo.png') 

Gets the screenshot of the current element as a base64 encoded string.

img_b64 = element.screenshot_as_base64 

Gets the screenshot of the current element as a binary data.

element_png = element.screenshot_as_png 

Simulates typing into the element.

  • value — A string for typing, or setting form fields. For setting file inputs, this could be a local file path.

Use this to send simple key events or to fill out form fields:

form_textfield = driver.find_element(By.NAME, 'username') form_textfield.send_keys("admin") 

This can also be used to set file inputs.

file_input = driver.find_element(By.NAME, 'profilePic') file_input.send_keys("path/to/profilepic.gif") # Generally it's better to wrap the file path in one of the methods # in os.path to return the actual path to support cross OS testing. # file_input.send_keys(os.path.abspath("path/to/profilepic.gif")) 

Returns a shadow root of the element if there is one or an error. Only works from Chromium 96, Firefox 96, and Safari 16.4 onwards.

This element’s tagName property.

value_of_css_property ( property_name ) → str [source] ¶

The value of a CSS property.

Источник

selenium.webdriver.remote.webelement¶

ABC’s will allow custom types to be registered as a WebElement to pass type checks.

class selenium.webdriver.remote.webelement. WebElement ( parent, id_ ) [source] ¶

Generally, all interesting operations that interact with a document will be performed through this interface.

All method calls will do a freshness check to ensure that the element reference is still valid. This essentially determines whether 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.

Returns the ARIA Level of the current webelement.

Returns the ARIA role of the current web element.

Clears the text if it’s a text entry element.

find_element ( by=’id’, value=None ) → selenium.webdriver.remote.webelement.WebElement [source] ¶

Find an element given a By strategy and locator.

element = element.find_element(By.ID, 'foo') 

Find elements given a By strategy and locator.

element = element.find_elements(By.CLASS_NAME, 'foo') 

Gets the given attribute or property of the element.

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.

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.

To obtain the exact value of the attribute or property, use get_dom_attribute() or get_property() methods respectively.

# Check if the "active" CSS class is applied to an element. is_active = "active" in target_element.get_attribute("class") 

Gets the given attribute of the element. Unlike get_attribute() , this method only returns attributes declared in the element’s HTML markup.

text_length = target_element.get_dom_attribute("class") 

Gets the given property of the element.

text_length = target_element.get_property("text_length") 

Internal ID used by selenium.

This is mainly for internal use. Simple use cases such as checking if 2 webelements refer to the same element, can be done using == :

if element1 == element2: print("These 2 are equal") 

Whether the element is visible to a user.

Returns whether the element is enabled.

Returns whether the element is selected.

Can be used to check if a checkbox or radio button is selected.

The location of the element in the renderable canvas.

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.

Returns the top lefthand corner location on the screen, or zero coordinates if the element is not visible.

Internal reference to the WebDriver instance this element was found from.

A dictionary with the size and location of the element.

screenshot ( filename ) → bool [source] ¶

Saves a screenshot of the current element to a PNG image file. Returns False if there is any IOError, else returns True. Use full paths in your filename.

  • filename: The full path you wish to save your screenshot to. This should end with a .png extension.
element.screenshot('/Screenshots/foo.png') 

Gets the screenshot of the current element as a base64 encoded string.

img_b64 = element.screenshot_as_base64 

Gets the screenshot of the current element as a binary data.

element_png = element.screenshot_as_png 

Simulates typing into the element.

  • value — A string for typing, or setting form fields. For setting file inputs, this could be a local file path.

Use this to send simple key events or to fill out form fields:

form_textfield = driver.find_element(By.NAME, 'username') form_textfield.send_keys("admin") 

This can also be used to set file inputs.

file_input = driver.find_element(By.NAME, 'profilePic') file_input.send_keys("path/to/profilepic.gif") # Generally it's better to wrap the file path in one of the methods # in os.path to return the actual path to support cross OS testing. # file_input.send_keys(os.path.abspath("path/to/profilepic.gif")) 

Returns a shadow root of the element if there is one or an error. Only works from Chromium 96, Firefox 96, and Safari 16.4 onwards.

This element’s tagName property.

value_of_css_property ( property_name ) → str [source] ¶

The value of a CSS property.

Источник

Читайте также:  Все теги для php
Оцените статью