1

I have following html:

<input id="!T1319457706_SPY" type="checkbox" name="!T1319457706_SPY" class="checkbox" onclick="toggleTextField(['1319457706'],this.checked,'','');" style="">

This is checkbox that I want to click,I have tried all the selector to locate it,but all failed and system have no error message,in this page I have tried to click other element,it works,expect this checkbox.

I have tried follow ways:

driver.find_element_by_id('!T1319457706_SPY').click()
driver.find_element_by_css_selector("input[name='!T1319457706_SPY']").click()
driver.find_element_by_xpath("//body[@class='grdtradeOrder']//form[@name='displayopenorders']//table[@class='t0']//tr[@name='orderid1319457706']//input[@name='!T1319457706_SPY']").click()

I also tried use:

 click_check=driver.find_element_by_id('!T1319457706_SPY')

 driver.execute_script("arguments[0].click();", click_check)

All above tries have failed.Any friend can help?

William
  • 3,724
  • 9
  • 43
  • 76

2 Answers2

1

I guess that clicking the checkbox calls a javascript code as seen from the onClick expression in the HTML code.

You could directly execute that javascript code using the execute_script function

driver.execute_script(""toggleTextField(['1319457706'],this.checked,'','');")

Or maybe this answer could help you. This clicks on the checkbox using Javascript.

Prashant Sengar
  • 506
  • 1
  • 7
  • 24
0
click_check = driver.find_element_by_css_selector("input[onclick*='toggleTextField']")
driver.execute_script("arguments[0].click();", click_check)
William
  • 3,724
  • 9
  • 43
  • 76