我有多個單選按鈕,我正在尋找的是獲得Tilte並單擊每個div的單選按鈕。 這是HTML。基於文本訪問電臺裏面的div
<div id="iff-campaigns">
<div id="iff-campaign52249" class="iff-campaign-container iffhidden" onmouseover="IffAdvertismentAction(52249,"over");" onmouseout="IffAdvertismentAction(52249,"out");">
<div class="iff-title">Would you like to get paid to take Surveys and Fun IQ Tests?</div>
<div class="iff-optin">
<label>
<input type="radio" name="iffinput-52249" id="iffinputyes-52249" value="Yes" onclick="IffAdvertismentSelect(52249,false,"",false);">Yes</label>
<label>
<input type="radio" name="iffinput-52249" id="iffinputno-52249" value="No" onclick="IffAdvertismentSelect(52249,false,"",false);">No</label>
</div>
<div id="div-cq52249" class="iff-div-customquestions-survey">
<div class="clear"></div>
<div id="div-first5224915243" class="iff-customquestion">
<div class="iff-cqlabel"> <span>* </span> First Name: </div>
<div class="iff-cqcontrol">
<input type="text" id="ifffirst~52249~15243" name="ifffirst~52249~15243" value="" class="iff-input-text" onblur="Ifffieldchange("ifffirst~52249~15243","first",1,1);" regfld=""> </div>
</div>
<div class="clear"></div>
<div id="div-last5224915244" class="iff-customquestion">
<div class="iff-cqlabel"> <span>* </span> Last Name: </div>
<div class="iff-cqcontrol">
<input type="text" id="ifflast~52249~15244" name="ifflast~52249~15244" value="" class="iff-input-text" onblur="Ifffieldchange("ifflast~52249~15244","last",1,1);" regfld=""> </div>
</div>
<div class="clear"></div>
<div id="div-email5224915245" class="iff-customquestion">
<div class="iff-cqlabel"> <span>* </span> Email Address: </div>
<div class="iff-cqcontrol">
<input type="text" id="iffemail~52249~15245" name="iffemail~52249~15245" value="" class="iff-input-text" onblur="Ifffieldchange("iffemail~52249~15245","email",1,1);" regfld="^[^<>[email protected]]+(@[^<>[email protected]]+(.[^<>[email protected]]+)+)$"> </div>
</div>
<div class="clear"></div>
</div>
<div id="iff-rollup52249" class="iff-roleup"> </div>
</div>
<div id="iff-campaign52706" class="iff-campaign-container" onmouseover="IffAdvertismentAction(52706,"over");" onmouseout="IffAdvertismentAction(52706,"out");">
<div class="iff-title">Would you like the days important news broken down into a quick and informative read each morning?</div>
<div class="iff-optin">
<label>
<input type="radio" name="iffinput-52706" id="iffinputyes-52706" value="Yes" onclick="IffAdvertismentSelect(52706,false,"",false);">Yes</label>
<label>
<input type="radio" name="iffinput-52706" id="iffinputno-52706" value="No" onclick="IffAdvertismentSelect(52706,false,"",false);">No</label>
</div>
<div id="div-cq52706" class="iff-div-customquestions-survey">
<div class="clear"></div>
<div id="div-email5270620435" class="iff-customquestion">
<div class="iff-cqlabel"> <span>* </span> Email Address: </div>
<div class="iff-cqcontrol">
<input type="text" id="iffemail~52706~20435" name="iffemail~52706~20435" value="" class="iff-input-text" onblur="Ifffieldchange("iffemail~52706~20435","email",1,1);" regfld="^[^<>[email protected]]+(@[^<>[email protected]]+(.[^<>[email protected]]+)+)$"> </div>
</div>
<div class="clear"></div>
</div>
<div id="iff-rollup52706" class="iff-roleup"> </div>
</div>
<div id="iff-campaign52912" class="iff-campaign-container" onmouseover="IffAdvertismentAction(52912,"over");" onmouseout="IffAdvertismentAction(52912,"out");">
<div class="iff-title">Ready to take cooking to the next level? </div>
<div class="iff-optin">
<label>
<input type="radio" name="iffinput-52912" id="iffinputyes-52912" value="Yes" onclick="IffAdvertismentSelect(52912,false,"",false);">Yes</label>
<label>
<input type="radio" name="iffinput-52912" id="iffinputno-52912" value="No" onclick="IffAdvertismentSelect(52912,false,"",false);">No</label>
</div>
<div id="div-cq52912" class="iff-div-customquestions-survey">
<div class="clear"></div>
<div id="div-first5291222515" class="iff-customquestion">
<div class="iff-cqlabel"> <span>* </span> First Name: </div>
<div class="iff-cqcontrol">
<input type="text" id="ifffirst~52912~22515" name="ifffirst~52912~22515" value="" class="iff-input-text" onblur="Ifffieldchange("ifffirst~52912~22515","first",1,1);" regfld=""> </div>
</div>
<div class="clear"></div>
<div id="div-last5291222516" class="iff-customquestion">
<div class="iff-cqlabel"> <span>* </span> Last Name: </div>
<div class="iff-cqcontrol">
<input type="text" id="ifflast~52912~22516" name="ifflast~52912~22516" value="" class="iff-input-text" onblur="Ifffieldchange("ifflast~52912~22516","last",1,1);" regfld=""> </div>
</div>
<div class="clear"></div>
<div id="div-email5291222517" class="iff-customquestion">
<div class="iff-cqlabel"> <span>* </span> Email Address: </div>
<div class="iff-cqcontrol">
<input type="text" id="iffemail~52912~22517" name="iffemail~52912~22517" value="" class="iff-input-text" onblur="Ifffieldchange("iffemail~52912~22517","email",1,1);" regfld="^[^<>[email protected]]+(@[^<>[email protected]]+(.[^<>[email protected]]+)+)$"> </div>
</div>
<div class="clear"></div>
<div id="div-zip5291222522" class="iff-customquestion">
<div class="iff-cqlabel"> <span>* </span> Zip: </div>
<div class="iff-cqcontrol">
<input type="text" id="iffzip~52912~22522" name="iffzip~52912~22522" value="" class="iff-input-text" onblur="Ifffieldchange("iffzip~52912~22522","zip",1,1);" regfld="(^d{5}$)|(^d{5}-d{4}$)|^([ABCEGHJKLMNPRSTVXY]d[ABCEGHJKLMNPRSTVWXYZ])+{0,1}(d[ABCEGHJKLMNPRSTVWXYZ]d)$"> </div>
</div>
<div class="clear"></div>
</div>
<div id="iff-rollup52912" class="iff-roleup"> </div>
</div>
<div id="iff-campaign52230" class="iff-campaign-container" onmouseover="IffAdvertismentAction(52230,"over");" onmouseout="IffAdvertismentAction(52230,"out");">
<div class="iff-title">Would you like to receive FREE Severe Local Weather Alerts straight to your inbox? These can be life saving! </div>
<div class="iff-optin">
<label>
<input type="radio" name="iffinput-52230" id="iffinputyes-52230" value="Yes" onclick="IffAdvertismentSelect(52230,false,"",false);">Yes</label>
<label>
<input type="radio" name="iffinput-52230" id="iffinputno-52230" value="No" onclick="IffAdvertismentSelect(52230,false,"",false);">No</label>
</div>
<div id="div-cq52230" class="iff-div-customquestions-survey">
<div class="clear"></div>
<div id="div-email5223015020" class="iff-customquestion">
<div class="iff-cqlabel"> <span>* </span> Email Address: </div>
<div class="iff-cqcontrol">
<input type="text" id="iffemail~52230~15020" name="iffemail~52230~15020" value="" class="iff-input-text" onblur="Ifffieldchange("iffemail~52230~15020","email",1,1);" regfld="^[^<>[email protected]]+(@[^<>[email protected]]+(.[^<>[email protected]]+)+)$"> </div>
</div>
<div class="clear"></div>
<div id="div-zip5223015025" class="iff-customquestion">
<div class="iff-cqlabel"> <span>* </span> Zip: </div>
<div class="iff-cqcontrol">
<input type="text" id="iffzip~52230~15025" name="iffzip~52230~15025" value="" class="iff-input-text" onblur="Ifffieldchange("iffzip~52230~15025","zip",1,1);" regfld="(^d{5}$)|(^d{5}-d{4}$)|^([ABCEGHJKLMNPRSTVXY]d[ABCEGHJKLMNPRSTVWXYZ])+{0,1}(d[ABCEGHJKLMNPRSTVWXYZ]d)$"> </div>
</div>
<div class="clear"></div>
</div>
<div id="iff-rollup52230" class="iff-roleup"> </div>
</div>
</div>
我試着以下但不工作:
//div[contains(text(),'" +textvalue+ "')]/preceding:://input[@value='Yes'])
我需要提取文本,並點擊單選按鈕,每格。
List<WebElement> camp2 = driver.findElements(By.className("iff-title"));
System.out.println(camp2.size());
for (WebElement title2: camp2)
{
System.out.println("Camp Title - "+title2.getText());
String text = title2.getText();
if(text.isEmpty())
{
System.out.println("Null Value found");
}
else
{
WebElement div = driver.findElement(By.xpath("//div[contains(text(),'"+text+"')]"));
div.findElement(By.xpath("//input[@value='Yes']")).click();
System.out.println("In Else loop.");
}
//div[contains(text(),'Would you like a Gift Card for a FREE Website, Blog or Online Store?')]
}
燦你只是解釋furthur – Piyush
關於什麼, –
我需要點擊單選按鈕,這是存在於div中,問題是有多個具有相同ID的div,所以我想出的是鎖定基於文本的div,然後移動到該div中的無線電元件,然後單擊它。 –