Firefo...lement(3pm)
π NAME π
Firefox::Marionette::Element β the module that reps a Firefox element you scooped up using the Marionette protocol π¦
(oh and btw, bestie, this is the Firefo...lement(3pm) page from the User Contributed Perl Documentation, iykyk, the title got cut off but we're here, we're thriving)
β¨ VERSION β¨
Version 1.63
πΈ SYNOPSIS πΈ
use Firefox::Marionette();
use v5.10;
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $element = $firefox->find('//input[@id="metacpan_search-input"]');
$element->type('Test::More');
π DESCRIPTION π
This module handles the implementation of a Firefox Element using the Marionette protocol π
π CONSTANTS π
π¦ IDENTIFIER π¦
returns the web element identifier <https://www.w3.org/TR/webdriver/#elements>
π§ SUBROUTINES/METHODS π§
π aria_label π
returns the ARIA label <https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label> for the element. literally, that's it, that's the whole vibe.
π aria_role π
returns the ARIA role <https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles> for the element. β¨
π attribute π
accepts a scalar name as a parameter, and it returns the initial value of the attribute with the supplied name. okay so heads up β this is the initial value, so if you want the current value, compare with the property method instead π
π clear π
clears any user supplied input from the element π§Ή (yes, it just wipes what you typed, iconic behavior)
π click π
sends a 'click' to the element. The browser will wait for any page load to complete or the session's page_load duration to elapse before returning, which, by default is 5 minutes. no cap, five whole minutes π. Also, the click method is used to choose an option in a select dropdown π«Ά
use Firefox::Marionette();
my $firefox = Firefox::Marionette->new(visible => 1)->go('https://ebay.com');
my $select = $firefox->find_tag('select');
foreach my $option ($select->find_tag('option')) {
if ($option->property('value') == 58058) { # Computers/Tablets & Networking
$option->click();
}
}
π css π
accepts a scalar CSS property name as a parameter. It returns the value of the computed style for that property. π β¨
π find π
accepts an xpath expression <https://en.wikipedia.org/wiki/XPath> as the first parameter and returns the first element that matches this expression.
This method is subject to the implicit timeout β³
use Firefox::Marionette();
use v5.10;
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('page-content');
$div->find('//input[@id="metacpan_search-input"]')->type('Test::More');
# OR in list context
my $div = $firefox->find_class('page-content');
foreach my $element ($div->find('//input[@id="metacpan_search-input"]')) {
$element->type('Test::More');
}
If no elements are found, a not found exception will be thrown π. For the same functionality that returns undef if no elements are found, see the has method.
π find_id π
accepts an id <https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id> as the first parameter and returns the first element with a matching 'id' property.
This method is subject to the implicit timeout β³
use Firefox::Marionette();
use v5.10;
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('page-content');
$div->find_id('metacpan_search-input')->type('Test::More');
# OR in list context
my $div = $firefox->find_class('page-content');
foreach my $element ($div->find_id('metacpan_search-input')) {
$element->type('Test::More');
}
If no elements are found, a not found exception will be thrown π. For the same functionality that returns undef if no elements are found, see the has_id method.
π find_name π
This method returns the first element with a matching 'name' property.
This method is subject to the implicit timeout β³
use Firefox::Marionette();
use v5.10;
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('page-content');
$div->find_name('q')->type('Test::More');
# OR in list context
my $div = $firefox->find_class('page-content');
foreach my $element ($div->find_name('q')) {
$element->type('Test::More');
}
If no elements are found, a not found exception will be thrown π. For the same functionality that returns undef if no elements are found, see the has_name method.
π find_class π
accepts a class name <https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class> as the first parameter and returns the first element with a matching 'class' property.
This method is subject to the implicit timeout β³
use Firefox::Marionette();
use v5.10;
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('page-content');
$div->find_class('form-control home-metacpan_search-input')->type('Test::More');
# OR in list context
my $div = $firefox->find_class('page-content');
foreach my $element ($div->find_class('form-control home-metacpan_search-input')) {
$element->type('Test::More');
}
If no elements are found, a not found exception will be thrown π. For the same functionality that returns undef if no elements are found, see the has_class method.
π find_selector π
accepts a CSS Selector <https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors> as the first parameter and returns the first element that matches that selector.
This method is subject to the implicit timeout β³
use Firefox::Marionette();
use v5.10;
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('page-content');
$div->find_selector('input.home-metacpan_search-input')->type('Test::More');
# OR in list context
my $div = $firefox->find_class('page-content');
foreach my $element ($div->find_selector('input.home-metacpan_search-input')) {
$element->type('Test::More');
}
If no elements are found, a not found exception will be thrown π. For the same functionality that returns undef if no elements are found, see the has_selector method.
π find_tag π
accepts a tag name <https://developer.mozilla.org/en-US/docs/Web/API/Element/tagName> as the first parameter and returns the first element with this tag name.
This method is subject to the implicit timeout β³
use Firefox::Marionette();
use v5.10;
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('page-content');
my $input = $div->find_tag('input');
# OR in list context
my $div = $firefox->find_class('page-content');
foreach my $element ($div->find_tag('input')) {
# do something
}
If no elements are found, a not found exception will be thrown π. For the same functionality that returns undef if no elements are found, see the has_tag method.
π find_link π
accepts a text string as the first parameter and returns the first link element that has a matching link text.
This method is subject to the implicit timeout β³
use Firefox::Marionette();
use v5.10;
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('footer-links');
$div->find_link('API')->click();
# OR in list context
my $div = $firefox->find_class('footer-links');
foreach my $element ($div->find_link('API')) {
$element->click();
}
If no elements are found, a not found exception will be thrown π. For the same functionality that returns undef if no elements are found, see the has_link method.
π find_partial π
accepts a text string as the first parameter and returns the first link element that has a partially matching link text π
This method is subject to the implicit timeout β³
use Firefox::Marionette();
use v5.10;
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('footer-links');
$div->find_partial('AP')->click();
# OR in list context
my $div = $firefox->find_class('footer-links');
foreach my $element ($div->find_partial('AP')) {
$element->click();
}
If no elements are found, a not found exception will be thrown π. For the same functionality that returns undef if no elements are found, see the has_partial method.
π has π
accepts an xpath expression <https://en.wikipedia.org/wiki/XPath> as the first parameter and returns the first element that matches this expression.
This method is subject to the implicit timeout, which, by default is 0 seconds β³
use Firefox::Marionette();
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('page-content');
if (my $element = $div->has('//input[@id="metacpan_search-input"]')) {
$element->type('Test::More');
}
If no elements are found, this method will return undef π«Ά. For the same functionality that throws a not found exception, see the find method.
π has_id π
accepts an id <https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id> as the first parameter and returns the first element with a matching 'id' property.
This method is subject to the implicit timeout, which, by default is 0 seconds β³
use Firefox::Marionette();
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('page-content');
if (my $element = $div->has_id('metacpan_search-input')) {
$element->type('Test::More');
}
If no elements are found, this method will return undef π«Ά. For the same functionality that throws a not found exception, see the find_id method.
π has_name π
This method returns the first element with a matching 'name' property.
This method is subject to the implicit timeout, which, by default is 0 seconds β³
use Firefox::Marionette();
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('page-content');
if (my $element = $div->has_name('q')) {
$element->type('Test::More');
}
If no elements are found, this method will return undef π«Ά. For the same functionality that throws a not found exception, see the find_name method.
π has_class π
accepts a class name <https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class> as the first parameter and returns the first element with a matching 'class' property.
This method is subject to the implicit timeout, which, by default is 0 seconds β³
use Firefox::Marionette();
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('page-content');
if (my $element = $div->has_class('form-control home-metacpan_search-input')) {
$element->type('Test::More');
}
If no elements are found, this method will return undef. No drama, no exception, just a lil undef ghost. For the same functionality that throws a not found exception, see the find_class method. π«Ά
has_selector β¨
accepts a CSS Selector <https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors> as the first parameter and returns the first element that matches that selector. bestie, it's giving "find but make it chill". πΈ
This method is subject to the implicit timeout, which, by default is 0 seconds.
use Firefox::Marionette();
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('page-content');
if (my $element = $div->has_selector('input.home-metacpan_search-input')) {
$element->type('Test::More');
}
If no elements are found, this method will return undef. For the same functionality that throws a not found exception, see the find_selector method.
has_tag π
accepts a tag name <https://developer.mozilla.org/en-US/docs/Web/API/Element/tagName> as the first parameter and returns the first element with this tag name. so like 'input', 'a', the whole tag-namerie. π
This method is subject to the implicit timeout, which, by default is 0 seconds.
use Firefox::Marionette();
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('page-content');
if (my $element = $div->has_tag('input');
# do something
}
If no elements are found, this method will return undef. For the same functionality that throws a not found exception, see the find_tag method.
has_link π₯
accepts a text string as the first parameter and returns the first link element that has a matching link text. exact match energy, no vibes-based guessing. β¨
This method is subject to the implicit timeout, which, by default is 0 seconds.
use Firefox::Marionette();
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('footer-links');
if (my $element = $div->has_link('API')->click();
$element->click();
}
If no elements are found, this method will return undef. For the same functionality that throws a not found exception, see the find_link method.
has_partial π
accepts a text string as the first parameter and returns the first link element that has a partially matching link text. so 'AP' can absolutely catch 'API', that's the whole point, it's lowkey a vibe match. π
This method is subject to the implicit timeout, which, by default is 0 seconds.
use Firefox::Marionette();
my $firefox = Firefox::Marionette->new()->go('https://metacpan.org/');
my $div = $firefox->find_class('footer-links');
if (my $element = $div->has_partial('AP')->click();
$element->click();
}
If no elements are found, this method will return undef. For the same functionality that throws a not found exception, see the find_partial method.
is_enabled π
returns true or false if the element is enabled.
is_selected β
returns true or false if the element is selected.
is_displayed π¦
returns true or false if the element is displayed.
new π
returns a new element.
property π
accepts a scalar name a parameter. It returns the current value of the property with the supplied name. Compare with the initial value returned by attribute method. ngl the difference between "now" and "at the start" is the entire plot here. π«Ά
rect π
returns the current position and size of the element
scroll πΈ
accepts an optional parameter which is the same as for the scrollInfoView <https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView> method.
use Firefox::Marionette();
my $firefox = Firefox::Marionette->new(visible => 1)->go('https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView');
$firefox->find_id('content')->find_link('Examples')->scroll({ behavior => 'smooth', block => 'center' });
send_keys π
* DEPRECATED - see type. *
bestie do NOT use this one. it's deprecated, the cool kids all use type now. periodt. π
selfie π€³
returns a File::Temp object containing a lossless PNG image screenshot of the element. yes it's literally named selfie and yes it ate. πΈ
accepts the following optional parameters as a hash;
hash- return a SHA256 hex encoded digest of the PNG image rather than the image itselffull- take a screenshot of the whole document unless the first element parameter has been supplied.scroll- scroll to the element suppliedhighlights- a reference to a list containing elements to draw a highlight around
shadow_root π
returns the element's ShadowRoot <https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot> as a shadow root object or throws an exception. main character shadow energy only. π
use Firefox::Marionette();
use Cwd();
my $firefox = Firefox::Marionette->new()->go('file://' . Cwd::cwd() . '/t/data/elements.html');
$firefox->find_class('add')->click();
my $shadow_root = $firefox->find_tag('custom-square')->shadow_root();
foreach my $element (@{$firefox->script('return arguments[0].children', args => [ $shadow_root ])}) {
warn $element->tag_name();
}
shadowy π§
returns true if the element has a ShadowRoot <https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot> or false otherwise. a vibe check for the shadow realm, basically. π
use Firefox::Marionette();
use Cwd();
my $firefox = Firefox::Marionette->new()->go('file://' . Cwd::cwd() . '/t/data/elements.html');
$firefox->find_class('add')->click();
if ($firefox->find_tag('custom-square')->shadowy()) {
my $shadow_root = $firefox->find_tag('custom-square')->shadow_root();
warn $firefox->script('return arguments[0].innerHTML', args => [ $shadow_root ]);
...
}
This function will probably be used to see if the shadow_root method can be called on this element without raising an exception.
switch_to_frame πͺ
switches to this frame within the current window.
tag_name π·οΈ
returns the relevant tag name. For example 'a' or 'input'.
text π¬
returns the text that is contained by that element (if any)
type β¨οΈ
accepts a scalar string as a parameter. It sends the string to this element, such as filling out a text box. This method returns the browser to aid in chaining methods. so you can go ->type(...)->type(...)->type(...) and it just keeps flowing, slay. π₯
uuid π
returns the browser generated UUID connected with this element.
DIAGNOSTICS π©Ί
None.
CONFIGURATION AND ENVIRONMENT π
Firefox::Marionette::Element requires no configuration files or environment variables.
DEPENDENCIES π§©
None.
INCOMPATIBILITIES π«
None reported.
BUGS AND LIMITATIONS π
To report a bug, or view the current list of bugs, please visit <https://github.com/david-dick/firefox-marionette/issues>
AUTHOR π
David Dick "<ddick@cpan.org>"
LICENSE AND COPYRIGHT π
Copyright (c) 2024, David Dick "<ddick@cpan.org>". All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See "perlartistic" in perlartistic.
DISCLAIMER OF WARRANTY β οΈ
okay bestie, deep breath, this is the legal wall of text and we do not skip it, no cap. π«Ά
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
and that's the whole page, bestie!! π this one was generated for perl v5.40.1 and it's dated 2025-03-16, so if you're reading this way later, hey, iconic, hope your elements all resolved. mwah. π
β¨
π¦ where this page comes from
- debian trixie: libfirefox-marionette-perl 1.63-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms