我一直在使用 Selenium IDE 和 Selenium Remote Driver 来测试一个网站。当我将文件导出到 perl 并尝试运行它时,尝试打开 Javascript 链接时出现错误。这是我一直在尝试的代码:
#!/usr/bin/perl
use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;
use Env;
my $sel = Test::WWW::Selenium->new( host => "localhost",
port => 4444,
browser => "*firefox",
browser_url => "http://cpc.cs.qub.ac.uk/" );
$sel->open_ok("http://cpc.cs.qub.ac.uk/" , undef, "Getting Webpage CPC");
$sel->set_speed("1000");
$sel->wait_for_page_to_load_ok("10000");
$sel->select_frame_ok("toolbar");
$sel->click_ok(" //a[contains(\@href,'javascript:goTo(overview.html');)] ");
#and tried this format as well
$sel->click_ok("//a[\@href='javascript:goTo('overview.html');']");
$sel->wait_for_page_to_load_ok("10000");
它说找不到元素,我一直在尝试使用 Xpath 作为定位器,但似乎无法定位。以下是我尝试单击的链接的 html:
<title>CPC Toolbar</title>
<script language="javascript" src="./toolbar.js"></script>
<tr>
<td align="center" >
<a href="javascript:goTo('overview.html');" onMouseover="libserv.src='icons/redlibserv.gif'" onMouseout="libserv.src='icons/bluelibserv.gif'"><IMG SRC="icons/bluelibserv.gif" name="libserv" width="100" height="20" border="0">
</a>
</td>
</tr>
任何有关如何实现这一点的帮助将不胜感激。在 WWW::Selenium 模块中,它提供了这些 xpath 格式以用作定位器:
xpath=//img[@alt='The image alt text']
xpath=//table[@id='table1']//tr[4]/td[2]
xpath=//a[contains(@href,'#id1')]
xpath=//a[contains(@href,'#id1')]/@class
xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td
xpath=//input[@name='name2' and @value='yes']
xpath=//*[text()="right"]