0

Target Checkbox

This is the HTML code of the Checkbox alone:

<table id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True" border="0">
			<tbody><tr>
				<td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_0" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$0"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_0">Cracked Case</label></td><td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_1" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$1"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_1">Cracked Case (Upper Half)</label></td>
			</tr><tr>
				<td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_2" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$2"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_2">Cracked Face Plate</label></td><td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_3" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$3"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_3">Deep Scratches</label></td>
			</tr><tr>
				<td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_4" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$4"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_4">Discolored Case</label></td><td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_5" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$5"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_5">Light Scratches In Case</label></td>
			</tr><tr>
				<td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_6" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$6"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_6">Major Cracks</label></td><td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_7" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$7"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_7">Major Scratches</label></td>
			</tr><tr>
				<td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_8" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$8"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_8">Minor Cracks</label></td><td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_9" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$9"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_9">Minor Scratches</label></td>
			</tr><tr>
				<td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_10" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$10"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_10">Missing Port Cover</label></td><td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_11" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$11"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_11">Missing Side Panel</label></td>
			</tr><tr>
				<td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_12" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$12"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_12">No Back Cover</label></td><td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_13" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$13"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_13">No Bay Cover</label></td>
			</tr><tr>
				<td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_14" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$14"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_14">No Face Plate</label></td><td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_15" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$15"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_15">Open Box</label></td>
			</tr><tr>
				<td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_16" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$16"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_16">Open Box, Sealed Unit</label></td><td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_17" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$17"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_17">Scratches In Screen</label></td>
			</tr><tr>
				<td><input id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_18" type="checkbox" name="rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38788_24582_73_0_True$18"><label for="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38788_24582_73_0_True_18">Sealed Box</label></td><td></td>
			</tr>
		</tbody></table>

Hello everyone! the problem is simple and complicated at the same time, in the pictures is my target to click, a checkbox which by all means should be easy to target but for some reason Python keeps throwing me this error (Which i encountered before but right now i can't bypass it):

Traceback (most recent call last):
  File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\Scripts\Add Asset.py", line 167, in <module>
    nobackcover = browser.find_element_by_xpath('//*[@id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38774_24566_73_0_True_12"]')
  File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 293, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element
    'value': value})['value']
  File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38774_24566_73_0_True_12"]"}
  (Session info: chrome=52.0.2743.116)
  (Driver info: chromedriver=2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129),platform=Windows NT 10.0.14393 x86_64)

Or variations if i am using name or id to target the checkbox.

When i copy the xpath after inspect element with Chrome developer tools this is what i get:

"//*[@id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38760_24576_73_0_True_12"]".

This is the code i am using currently:

#Here i open the checkbox menu that gives me the checkbox i need to click
Cosmeticselect = browser.find_element_by_xpath('//*[@id="rmaAssetCosmeticComponents_ctl00_btnAdd"]')
Cosmeticselect.click()
#2 seconds delay because it takes a second to load.
time.sleep(2)
#I have tried several iterations of this none give me the desire output, maybe this checkbox is in another iframe? if so i have yet to find it in the code.
nobackcover = browser.find_element_by_id('rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38776_24568_73_0_True_12')
#nobackcover = browser.find_element_by_xpath('//*[@id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38775_24567_73_0_True"]/tbody/tr[7]/td[1]/label')
#nobackcover = browser.find_element_by_name('rmaAssetCosmeticComponents$ctl00$CheckBoxList_Comp_17_38778_24570_73_0_True$12')
nobackcover.click()

I suspect that i have to switch to the cosmetics "window" but i have yet to find a reference to an iframe or the like, i will keep working on it and when i find i solution i will post it but if anyone is interested in adding a fresh pair of eyes to this problem i would appreciate it.

7
  • No offense, but my eyes are not "fresh" anymore after looking on the screenshot and the code :) Please leave only relevant part of the code in the question. Also, what if you right click element in developer tools and copy xpath - what do you get? Thanks. Commented Sep 21, 2016 at 16:52
  • And also let us know, element id attribute value is dynamically changing here or fixed?? Commented Sep 21, 2016 at 16:58
  • Updated the question. Surabh Gaur the element i think is fixed but i am not certain when i know for sure ill update question. Commented Sep 21, 2016 at 17:05
  • Could you share relevant HTML code?? And please make sure I'd is fixed or not just refreshing page multiple time and see id is changing or not?? Commented Sep 21, 2016 at 17:22
  • It would be interesting to see the entire html for the input.I am sure you cane find some distinct string in an attribute the you can use. Commented Sep 21, 2016 at 20:38

2 Answers 2

0

Until you update with the html code you can try these:

css
input[id*='rmaAssetCosmeticComponents'][id*='True_12']

xpath's
//input[text()='No Back Cover'] or
//input[contains(@id, 'rmaAssetCosmeticComponents')][contains(@id, 'True_12')]

Hopping that the last part of the id does not change, you can create a selector based on the parts of ht attribute that are not changing, or based on the text contained in the element.

3
  • Updated Question. Commented Sep 23, 2016 at 12:52
  • Seems that the middle part of the id might change, updated the answer accordingly. Commented Sep 23, 2016 at 13:05
  • Yes! It works! Thank you so much lauda, i swore that it was a static id, thanks for correcting me! Finally with that my script is complete! Commented Sep 23, 2016 at 13:10
0

First, make sure your path (//[@id="rmaAssetCosmeticComponents_ctl00_CheckBoxList_Comp_17_38774_24566_73_0_True_12") can pointed to correct element by using Selenium IDE

Second, use WebElement wait until the element is clickable or presence Of Element located

1
  • How do i use WebElement to wait for a clickable element? Because until now i have been using "Hard sleeps" to wait for 1 or 3 seconds. Commented Sep 23, 2016 at 12:53

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.