在ruby编程中选中selenium复选框

时间:2017-08-26 03:16:45

标签: ruby selenium selenium-webdriver selenium-chromedriver

我想在ruby编程中选中selenium复选框。 但我不能把检查。我该怎么办?

现在,我在下面编写代码。

# code
element = @driver.find_element(:xpath, '//*
[@id="lookCheck10"]/div[1]/div[2]/div[1]/label')
@driver.execute_script("arguments[0].click();", element); 



# html
<div class="e-select-box p-look-bike__type-box">
    <div class="e-title">
       <input type="hidden" name="data[Reserve][types][10]" 
  id="lookCheck10_" value="0"/><input type="checkbox" 
name="data[Reserve][types][10]"  id="lookCheck10" value="1" 
checked="checked"/>                         <label 
for="lookCheck10">BIKE</label>
    </div>
    <div class="e-media">
        <div class="e-media__body p-look-bike__type-detail">
            <p>this is good for family</p>
        </div>
        <div class="e-media__image p-look-bike__type-image">
            <img src="/images/reserve/img_biketype_10.jpg" alt="bike">
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

我假设您要选择带有“BIKE”标签的复选框。为此,请使用以下代码 -

element = @driver.find_element(:xpath, '//*[@id="lookCheck10"]')
@driver.execute_script("arguments[0].click();", element);