0
<div id="yui_3_16_0_1_1399697074576_1339" class="cbox " role="gridcell">
<input id="yui_3_16_0_1_1399697074576_1338" type="checkbox" tabindex="-1" 89513626107905="" aria-label="Message " title="Select this email">
<span id="yui_3_16_0_1_1399697074576_1340" class="icon"></span>
</div>`

The above HTML is from firebug.

I want to click the checkbox, its ID is id="yui_3_16_0_1_1399697074576_1338" from above. I tried using by.id and by.path, however neither of them work. The following is what I tried:

By.id("yui_3_16_0_1_1399697074576_1338")
By.xpath("//input[@id='yui_3_16_0_1_1399697074576_1339'

Can someone help me on this?

3
  • If you tried By.id | By.xpath with findElement and neither of them work than the selected id may be generated. Commented May 10, 2014 at 6:53
  • Sounds like the ID is dynamically generated. Commented May 10, 2014 at 8:55
  • Since the ID looks like it's dynamically generated you need to look for some distinct ids, classes or elements, such that you can find from them the div with the input. This can then be done for example with positional selector <some specific selector higher up>/div[1]/input[1]. Commented May 10, 2014 at 10:53

3 Answers 3

1

You NEVER want to match on an ID like that. What I'd recommend, is matching on something a little more "unique".

Try:

By.cssSelector("input[type='checkbox'][title='Select this email']")

This selector above will match your <input/> perfectly. And, it's not coupled with the Yahoo UI so if you or your developers ever change software, it will account for that.

Sign up to request clarification or add additional context in comments.

Comments

1

if the id is static :

 string checkboxXPath = "//input[contains(@id, 'yui_3_16_0_1_1399697074576_1338')]"

for Dynamic Tags value:

           string checkboxXPath = "//input[contains(@type,'checkbox') and                       
          contains(@title,'Select this email')]"

IWebElement elementToClick = driver.FindElement(By.XPath(checkboxXPath));
elementToClick.Click();

2 Comments

the ID value change everytime, so i cant use find ID. i need another way to do this
thank you loknath, thats what i did too, using 'contains(@title, 'Select this email'); i cant vote since i am new here
0

You have to get the element using the id and make a click. It is similar to button click

driver.findElement(By.id("yui_3_16_0_1_1399697074576_1338")).click();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.