我一直在使用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 ::硒模塊中,它給這些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"]
感謝。
您是否有此信息的來源? –
感謝user1697631。我也讀過那個。大多數人降級到FF21。所以我正在做這個過程。但是這似乎解決了他們大部分的問題。 – Hakim
Acutally,它似乎有一個修復程序,需要下載IDE 2.1.0。更多信息在這裏:https://code.google.com/p/selenium/issues/detail?id=5841 – Hakim