How do I return the text of a WebElement using Perl's
Selenium::Remote::Driver?
I feel like I must be missing something obvious. I know the XPath to a
WebElement and I want to compare the text in that element to some string.
Say the XPath for the element is /html/body/div/a/strong and I want to
compare it to $str.
So it shows up in source like ...<strong>find this string</strong>
So I say
use strict;
use warnings;
use Selenium::Remote::Driver;
# Fire up a Selenium object, get to the page, etc..
Test::More::ok($sel->find_element("/html/body/div/a") eq $str, "Text
matched");
When I run this the test fails when it should pass. When I try to print
the value of find_element($xpath) I get some hash reference. I've googled
around some and find examples telling me to try
find_element($xpath)->get_text() but get_text() isn't even a method in the
original package. Is it an obsolete method that used to actually work?
Most of the examples online for this module say "It's easy!" then show me
how to get_title() but not how to check the text at an XPath. I might be
going crazy.
No comments:
Post a Comment