Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl,Selenium::Remote::Driver—使用Xpath选择HTML表单中的第二个元素,其中两个元素具有相同的';价值';条目_Perl_Selenium_Selenium Rc - Fatal编程技术网

Perl,Selenium::Remote::Driver—使用Xpath选择HTML表单中的第二个元素,其中两个元素具有相同的';价值';条目

Perl,Selenium::Remote::Driver—使用Xpath选择HTML表单中的第二个元素,其中两个元素具有相同的';价值';条目,perl,selenium,selenium-rc,Perl,Selenium,Selenium Rc,我试图弄清楚如何在Seleniumn::Remote::Driver的Perl模块中正确使用XPATH。具体来说,我有一个HTML表单,它包含各种输入字段,其中两个输入字段具有相同的值。我想根据第二个输入字段的“值”(两个输入字段中的值相同)选择第二个输入字段。我在Selenium IDE(1.10.0)中尝试过这一点,它将目标显示为: xpath=(//input[@value='clickhere'])[2] 我试图在使用Selenium::Remote::Driver模块的Perl脚本

我试图弄清楚如何在Seleniumn::Remote::Driver的Perl模块中正确使用XPATH。具体来说,我有一个HTML表单,它包含各种输入字段,其中两个输入字段具有相同的值。我想根据第二个输入字段的“值”(两个输入字段中的值相同)选择第二个输入字段。我在Selenium IDE(1.10.0)中尝试过这一点,它将目标显示为:

 xpath=(//input[@value='clickhere'])[2]
我试图在使用Selenium::Remote::Driver模块的Perl脚本中模拟这种行为

$elem = $driver->find_element("xpath=(//input[\@value='clickhere'][2])");
$driver->mouse_move_to_location(element => $elem, xoffset => 0, yoffset => 0);  
$driver->click;
这不起作用,并引发错误(请参见下文)。我假设错误与“[2]”部分有关,因为我通常能够在HTML表单中选择具有唯一“值”的元素。将xpath编码到find_元素函数中的正确方法是什么,以便它选择并单击HTML表单中的第二个元素,其中第一个和第二个元素都具有值“cickhere”

Error while executing command: Argument was an invalid selector (e.g. XPath/CSS).: The given selector xpath=(//input[@value='click'][2]) is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: Unable to locate an element with the xpath expression xpath=(//input[@value='clickhere'][2]) because of the following error:
[Exception... "The expression cannot be converted to return the specified type."  code: "0" nsresult: "0x805b0034 (TypeError)"  location: "file:///C:/Temp/anonymous6984397347674679222webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js Line: 5696"]
Command duration or timeout: 16 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '2.30.0', revision: 'dc1ef9c', time: '2013-02-19 00:15:27'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_11'
Session ID: ce542470-8a3a-41da-a73a-2a55275290d3
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=19.0}] at C:\Perl\scripts\frontend\createAccount.pl line 144.
示例显示采用XPath的方法

定位器方案可以作为单独的参数传递,但这里不需要,因为默认值是
xpath

试一试

示例显示采用XPath的方法

定位器方案可以作为单独的参数传递,但这里不需要,因为默认值是
xpath

试一试


+1正确的建议,几乎正确的答案@CODEBLACK最初的定位符是
xpath=(//input[@value='clickhere'])[2]
,因此答案是
ind_元素('(//input[@value='clickhere'])[2])括号在这种情况下会有所不同。thx伙计们!这是我使用的最后一行(工作):elem=$driver->find\u元素((//input[\@value='clickhere'])[2];//input[position()=2和@value='clickhere']是否适合您?这可能是另一种选择,尽管我还没有尝试过。@Phil Perry,我发布的代码和Black发布的代码与第二个输入值
clickhere
相匹配。如果第二个输入的值为
单击此处
,则代码与之匹配。现在还不清楚CODEBLACK是什么意思,但他说他的代码是有效的…@ikegami嗨,我需要一些支持+1正确的建议,几乎正确的答案@CODEBLACK最初的定位符是
xpath=(//input[@value='clickhere'])[2]
,因此答案是
ind_元素('(//input[@value='clickhere'])[2])括号在这种情况下会有所不同。thx伙计们!这是我使用的最后一行(工作):elem=$driver->find\u元素((//input[\@value='clickhere'])[2];//input[position()=2和@value='clickhere']是否适合您?这可能是另一种选择,尽管我还没有尝试过。@Phil Perry,我发布的代码和Black发布的代码与第二个输入值
clickhere
相匹配。如果第二个输入的值为
单击此处
,则代码与之匹配。现在还不清楚CODEBLACK是什么意思,但他说他的代码是有效的…@ikegami嗨,我需要一些支持。
my $elem = $driver->find_element('//input[@value="clickhere"][2]');