[英]How to select more than one checkboxes based on passing values in Selenium WebDriver (Using Java)
Lets see the below scenario. 让我们来看看下面的场景。 On the registration form, there is field called "Hobbies" which has three check boxes "Reading", "Dance" and "Cricket". 在注册表上,有一个名为“爱好”的字段,其中包含三个复选框:“阅读”,“舞蹈”和“ C”。
I have to select two check boxes "Reading" and "Cricket". 我必须选中两个复选框“阅读”和“ C”。 I have to pass one string value (eg "Reading,Cricket") to one method say "selectMultipleCheckboxes". 我必须将一个字符串值(例如“ Reading,Cricket”)传递给一种方法,例如“ selectMultipleCheckboxes”。 So, based on passing value, it should split the string and it should select two check boxes. 因此,应根据传递的值拆分字符串,并应选中两个复选框。
Note: I don't want to select single check box or all check boxes. 注意:我不想选择单个复选框或所有复选框。
Could you please help me to write test script? 你能帮我写测试脚本吗?
I'm not really an expert on Java, but since someone just answered my question, I thought I would at least try to help you out. 我并不是Java方面的专家,但是由于有人刚刚回答了我的问题,我认为我至少会尽力帮助您。 You would do something like this: 您将执行以下操作:
String originalText = "Reading,Cricket";
String[] parts = originalText.split(",");
String readingPart = parts[0];
String cricketPart = parts[1];
Then you would pass those strings to Selenium: 然后将这些字符串传递给Selenium:
driver.findElement(By.id(cricketPart)).click();
That would of course be assuming your checkbox's DOM ID was called "Cricket" 那当然是假设您复选框的DOM ID被称为“ C”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.