![]() |
![]()
| ![]() |
![]()
NAMESelenium::Remote::WebElement - Representation of an HTML Element used by Selenium Remote DriverVERSIONversion 1.37DESCRIPTIONSelenium Webdriver represents all the HTML elements as WebElements. This module provides a mechanism to represent them as objects & perform various actions on the related elements. This module should not be instantiated directly by the end user. Selenium::Remote::Driver instantiates this module when required. Typically, the find_element method in Selenium::Remote::Driver returns this object on which various element related operations can be carried out.What is probably most useful on this page is the list of methods below that you can perform on an element once you've found one and S::R::D has made an instance of this for you. CONSTRUCTORnew
For typical usage of S::R::D and this module, none of this matters and it should Just Work without you having to worry about it at all. For further reading, the W3C spec <https://www.w3.org/TR/webdriver/#elements> strictly dictates the exact behavior. FUNCTIONSchild(selector, method)children(selector, method)Alias to Selenium::Remote::Driver::find_child_element and find_child_elements, respectively.clickDescription: Click the element. Usage: $elem->click(); submitDescription: Submit a FORM element. The submit command may also be applied to any element that is a descendant of a FORM element. Compatibility: On webdriver3 enabled servers, this uses a JS shim, which WILL NOT submit correctly unless your element is an <input>. Try clicking it if possible instead. Usage: $elem->submit(); send_keysDescription: Send a sequence of key strokes to an element. If you want to send specific Keyboard events, then use the WDKeys module along with theis method. See e.g. for reference Input: 1 Required: {ARRAY | STRING} - Array of strings or a string. Usage: $elem->send_keys('abcd', 'efg'); $elem->send_keys('hijk'); or # include the WDKeys module use Selenium::Remote::WDKeys; . . $elem->send_keys(KEYS->{'space'}, KEYS->{'enter'}); is_selectedDescription: Determine if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected. Output: BOOLEAN - whether the element is selected Usage: $elem->is_selected(); set_selectedDescription: Select an OPTION element, or an INPUT element of type checkbox or radiobutton. Forces selected=1 on the element.. Usage: $elem->set_selected(); toggleDescription: Toggle whether an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected. Output: BOOLEAN - Whether the element is selected after toggling its state. Usage: $elem->toggle(); is_enabledDescription: Determine if an element is currently enabled. Output: BOOLEAN - Whether the element is enabled. Usage: $elem->is_enabled(); get_element_locationDescription: Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. Compatibility: On WebDriver 3 enabled servers, this is an alias for get_element_rect(). Output: HASH - The X and Y coordinates for the element on the page. Usage: $elem->get_element_location(); This method is DEPRECATED on webdriver3 enabled servers. get_sizeDescription: Determine an element's size in pixels. The size will be returned with width and height properties. Compatibility: On WebDriver 3 enabled servers, this is an alias for get_element_rect(). Output: HASH - The width and height of the element, in pixels. Usage: $elem->get_size(); This method is DEPRECATED on webdriver3 enabled servers. get_element_rectGet the element's size AND location in a hash.Example Output: { x => 0, y => 0, height => 10, width => 10 } get_element_location_in_viewDescription: Determine an element's location on the screen once it has been scrolled into view. Note: This is considered an internal command and should only be used to determine an element's location for correctly generating native events. Compatibility: On Webdriver3 servers, we have to implement this with a JS shim. This means in some contexts, you won't get any position returned, as the element isn't considered an element internally. You may have to go up the element stack to find the element that actually has the bounding box. Output: {x:number, y:number} The X and Y coordinates for the element on the page. Usage: $elem->get_element_location_in_view(); get_tag_nameDescription: Query for an element's tag name. Output: STRING - The element's tag name, as a lowercase string. Usage: $elem->get_tag_name(); clearDescription: Clear a TEXTAREA or text INPUT element's value. Usage: $elem->clear(); get_attributeDescription: Get the value of an element's attribute. Compatibility: In older webDriver, this actually got the value of an element's property. If you want to get the initial condition (e.g. the values in the tag hardcoded in HTML), pass 1 as the second argument. Or, set $driver->{emulate_jsonwire} = 0 to not have to pass the extra arg. This can only done on WebDriver 3 enabled servers. Input: 2 Required: STRING - name of the attribute of the element Optional: BOOLEAN - "I really mean that I want the initial condition, quit being so compatible!!!" Output: {STRING | NULL} The value of the attribute, or null if it is not set on the element. Usage: $elem->get_attribute('name',1); get_propertyGets the "Current Value" of an element's attribute.Takes a named property as an argument. Only available on WebDriver 3 enabled servers. get_valueDescription: Query for the value of an element, as determined by its value attribute. Output: {STRING | NULL} The element's value, or null if it doesn't have a value attribute. Usage: $elem->get_value(); is_displayedDescription: Determine if an element is currently displayed. Note: This does *not* tell you an element's 'visibility' property; as it still takes up space in the DOM and is therefore considered 'displayed'. WC3 Compatibility: On JSONWire this method really only checked to see whether the element's style was display:none, or whether it was a hidden input. This is because "displayedness" was pretty loosely defined until fairly late on into the process, and much grief resulted. In WC3 webdriver, it additionally does a viewport check, to account for the firmer definition of "displayedness": https://w3c.github.io/webdriver/#element-displayedness Output: BOOLEAN - Whether the element is displayed. Usage: $elem->is_displayed(); is_hiddenDescription: Determine if an element is currently hidden. Output: BOOLEAN - Whether the element is hidden. Usage: $elem->is_hidden(); dragAlias for Selenium::ActionChains::drag_and_drop().Provide element you wish to drag to as argument. my $target = $driver->find_element('receptacle','id'); my $subject = $driver->find_element('thingy','id'); $subject->drag($target); get_textDescription: Get the innerText of the element. Output: STRING - innerText of an element Usage: $elem->get_text(); get_css_attributeDescription: Query the value of an element's computed CSS property. The CSS property to query should be specified using the CSS property name, not the JavaScript property name (e.g. background-color instead of backgroundColor). Input: 1 Required: STRING - name of the css-attribute Output: STRING - Value of the css attribute Usage: $elem->get_css_attribute('background-color'); describeDescription: Describe the identified element Usage: $elem->describe(); Note: DEPRECATED as of 2.42.2 -- use get_text, get_value, is_displayed, or whatever appropriate WebElement function you need instead Entirely unsupported on WebDriver 3 enabled servers. screenshotDescription: Get a screenshot of the visible region that is a subset of the element's bounding box as a base64 encoded image. Compatibility: Only available on Webdriver3 enabled selenium servers. Input (optional): $scroll_into_view - BOOLEAN default true. If false, will not scroll the element into the viewport first. Failing to do so may result in an image being cropped partially or entirely. Output: STRING - base64 encoded image Usage: print $element->screenshot(); To conveniently write the screenshot to a file, see "capture_screenshot". capture_screenshotDescription: Capture a screenshot of said element and save as a PNG to provided file name. Compatibility: Only available on Webdriver3 enabled selenium servers. Input (optional): $scroll_into_view - BOOLEAN default true. If false, will not scroll the element into the viewport first. Failing to do so may result in an image being cropped partially or entirely. Output: TRUE - (Screenshot is written to file) Usage: $element->capture_screenshot($filename); SEE ALSOPlease see those modules/websites for more information related to this module.
BUGSPlease report any bugs or feature requests on the bugtracker website <https://github.com/teodesian/Selenium-Remote-Driver/issues>When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. AUTHORSCurrent Maintainers:
Previous maintainers:
Original authors:
COPYRIGHT AND LICENSECopyright (c) 2010-2011 Aditya Ivaturi, Gordon ChildCopyright (c) 2014-2017 Daniel Gempesaw Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|