简体   繁体   中英

No able to select particular check box using Selenium (Java)

I want to click on Store Pickup Available checkbox on following page

http://www.target.com/c/pants-shorts-baby-toddler-boys-clothing/-/N-59yk1#navigation=true&viewType=medium&sortBy=newest&isleaf=true&navigationPath=59yk1&parentCategoryId=9976007&facetedValue=/-/N-59yk1&RatingFacet=0&categoryId=139007

And the particular HTML part has

<input type="checkbox" name="facetId" id="in store, onlineCheckbox3" 
value="10058540" omniture="Store Pickup Eligible">

I tried many thing By.id() , By.cssSelector() and xpath also.

Can someone try and tell me the working code ... in-between I will continue trying.

It will select By.id which you need to write

<input type="checkbox" name="facetId" id="facetId" 
value="10058540" omniture="Store Pickup Eligible">

The problem is the checkbox you want to click is hidden initially. You can click it with something like this:

driver.findElement(By.xpath("//a[contains(text(),'in store, online')]")).click();
driver.findElement(By.xpath("//span[contains(text(),'Store Pickup Eligible')]/../../input")).click();

This will expand the element "in store, online", then click the checkbox labelled "Store Pickup Eligible".

You can find this checkbox by CSS using: [id*='onlineCheckbox3'] . As Richard stated, you must click the category to show the element first. Find this by: [id=dimensions]>ul>li:nth-child(9) a . Sometimes clicking an a doesn't work (depending on the html structure), and you must click an element inside the anchor, swap that out for span and it should work. I prefer all CSS selectors when locating elements, but you can use whichever method you prefer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM