yoyo
yoyo

Reputation: 13

Put check this checkbox with selenium in ruby programing

I would like to put check this checkbox with selenium in ruby programing. but i can`t do put check. how should I do?

Now, I make below code.

# 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>

Upvotes: 0

Views: 346

Answers (1)

Kapil
Kapil

Reputation: 407

I am assuming you want to select a checkbox with label 'BIKE'. For that, use below code-

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

Upvotes: 1

Related Questions