-2

I have to check whether a particular text exists on a page using Selenium::Remote::Driver.

I want to enter a particular text in the search and check whether this text exists on the page

type a text in seach-box

my $such_inhalt = "fuer";
my $such=$driver->find_element("term","name");
$such->send_keys($such_inhalt);

search

$driver->find_element('//*[@id="searchsubmit"]')->click;

Result: check if the text found from search or not

perlfg
  • 59
  • 1
  • 7

1 Answers1

1

You can use get_page_source method to get page source (HTML) and then use Regex (or a Parser) to look for desired string/pattern.

use Selenium::Remote::Driver;
my $driver = Selenium::Remote::Driver->new;
$driver->get('http://www.perl.org');
my $search = 'find_this_term';
print "$search exists in page" if $driver->get_page_source() =~ /$search/;

If you are searching for the text at an exact location then you can do something like below:

$text = $driver->get_text("//div[\@name='q']");
print "Found text" if ($text eq 'find_this_term');
Chankey Pathak
  • 21,187
  • 12
  • 85
  • 133