请在下面两个选定的输入字段的HTML下方找到,但我需要选择第一个输入字段,然后在我的XPath下方找到-请提前帮助我
//*[contains(@id,'CC_CARD_NUMBER_!SEPARATOR') and
contains(@parentquestion,"|_VISA")]
首次输入
<input value="" class="form-control flleft fln masked" defaultvalue=""
id="CC_CARD_NUMBER_!SEPARATOR!_9beb0a0e-e089-4d9b-a7c3-75e69f40484c"
onclick="showChildQuestions(this);"
parentquestion="CC_CARD_TYPE_!SEPARATOR!_4185c1bd-b262-431e-a05d-c174f926a8bf_|_VISA"
questionid="CC_CARD_NUMBER_!SEPARATOR!_9beb0a0e-e089-4d9b-a7c3-75e69f40484c"
type="text" autocomplete="off" maxlength="16"
style="-webkit-text-security: disc;">
第二输入
<input value="" class="form-control flleft fln masked" defaultvalue=""
id="CC_CARD_NUMBER_!SEPARATOR!_3c59ab5f-a770-454a-8ee6-d76fc32a9dea"
onclick="showChildQuestions(this);"
parentquestion="CC_CARD_TYPE_!SEPARATOR!_e245a7f5-d623-4a79-ad42-e2ec6c8c0dbf_|_VISA"
questionid="CC_CARD_NUMBER_!SEPARATOR!_3c59ab5f-a770-454a-8ee6-d76fc32a9dea"
type="text" autocomplete="off" maxlength="16"
style="-webkit-text-security: disc;">
答案 0 :(得分:0)
您可以将xpath与索引一起使用:
(//*[contains(@id,'CC_CARD_NUMBER_!SEPARATOR') and contains(@parentquestion,"|_VISA")])[1]
(//*[contains(@id,'CC_CARD_NUMBER_!SEPARATOR') and contains(@parentquestion,"|_VISA")])[2]
或者您可以使用Selenium:
List<WebElement> inputs = driver.findElements(By.xpath("//*[contains(@id,'CC_CARD_NUMBER_!SEPARATOR') and contains(@parentquestion,"|_VISA")]"));
inputs.get(0).click();
inputs.get(1).click();
或者您可以在html中使用引用元素。