2

我正在将 selenium webdriver 与 java 一起使用,我无法从页面上总共 6 个类似元素中找到一个特定按钮。我尝试使用带有“value”属性的 XPath:-//input[@value = 'New PAN for Indian Citizens (Form 49A)'] 但无法找到该元素。所有 6 个按钮的 HTML 如下:-

<input type="submit" onclick="javascript:popitup('0','',false);" style="{width:22em}"      value=" New PAN for Indian Citizens (Form 49A) " name="submit">

<input type="submit" onclick="javascript:popitup('5','',false);" style="{width:22em}"     value=" New PAN for Foreign Citizens (Form 49AA) " name="submit">

<input type="submit" onclick="javascript:popitup('1','',false);" style="{width:22em}"     value="Changes or Correction in PAN details" name="submit">

<input type="submit" onclick="javascript:popitup('1','',false);" style="{width:22em}"     value=" Reprint of PAN card " name="submit">

<input type="submit" onclick="javascript:popitup('2','',false);" style="{width:22em}"     value=" Transaction Status Enquiry " name="submit">

<input type="submit" onclick="javascript:popitup('3','',false);" style="{width:22em}"     value=" Status Track for PAN application " name="submit">

请帮助我的人。. . 提前致谢

4

2 回答 2

0

或者您可以尝试部分匹配:

driver.findElement(By.xpath("//input[contains(value, '(Form 49A)')]"));
于 2013-10-18T07:30:28.747 回答
0

您应该以与 HTML 中提到的相同方式提及属性值,因此即使是空格也很重要...

driver.findElement(By.xpath("//input[@value=' New PAN for Indian Citizens (Form 49A) ']"));

或者

driver.findElement(By.cssSelector("input[value=' New PAN for Indian Citizens (Form 49A) ']"));
于 2013-10-15T13:06:05.220 回答