单击所有 ;[Ruby Selenium Web驱动程序]

单击所有 ;[Ruby Selenium Web驱动程序],ruby,selenium-webdriver,Ruby,Selenium Webdriver,下图所示的按钮有大量衬里。 按钮,或根据日期减少或增加。 “值”的内容只会更改 <input type="checkbox" value="021258" name="xbutton"></input> <input type="checkbox" value="084192" name="xbutton"></input> <input type="checkbox" value="095842" name="xbutton"><

下图所示的按钮有大量衬里。 按钮,或根据日期减少或增加。 “值”的内容只会更改

<input type="checkbox" value="021258" name="xbutton"></input>
<input type="checkbox" value="084192" name="xbutton"></input>
<input type="checkbox" value="095842" name="xbutton"></input>
<input type="checkbox" value="096325" name="xbutton"></input>
...
...

我首先保存了一个文件
test.html
,用于测试所有html部分,如下所示:


现在,为了选中这些复选框,我编写了如下代码:

driver=Selenium::WebDriver.for:firefox
driver.navigate.to“file:///home/kirti/workspace/Ruby/test.html"
元素到元素click=driver.find元素(:xpath,“//input[@name='xbutton']”)
#下面的代码将只选中以前未选中的复选框。
元素_to_click.each{e | e.click if e.attribute('checked').nil}
以下是截图:

driver.find_element(:name, "xbutton").click