-1

I am trying to click a small button, which has no "ID" or "Name", on a website. The only unique identifier is onclick, which is as follows:

onclick="submitForm('DefaultFormName',1,{'param1':'HXCTIMECARDACTIVITIESPAGEXgm7J5oT','serverValidate':'1uCdqvhJe','param2':'',event:'details|1'});return false;"

However, another button on the page has the following onclick:

onclick="submitForm('DefaultFormName',1,{'param1':'HXCTIMECARDACTIVITIESPAGEXgm7J5oT','serverValidate':'1uCdqvhJe','param2':'',event:'details|2'});return false;"

The only difference is a 1 vs. a 2 in the middle of the code. I tried to use a "find_element_by_css_selector" with the following code but it didn't work:

driver.find_element_by_css_selector(".x1p[onclick*='details|1']").click()

Another option would be selecting the preceding element, with the following code:

 precedingbutton = driver.find_element_by_name('B22_1_6')

And then sending tab and then enter. However, after I send Tab, I don't know of a way to send Enter without assigning the Send_Keys command back to the preceding box, which deselects the button I want.

Let me know if you can help!

2 Answers2

0

If you can locate the parent, you can locate the child, either with xpath or the nth-child css selector, relative to it.

Edit in response to comments:

Assuming by "2 elements away" you mean it is a sibling preceding the target, try something like td[name="B22_1_6"] + td + td. This is the sibling selector.

Silas Ray
  • 25,682
  • 5
  • 48
  • 63
  • The preceding box is not a parent, though. Just another element in the table. The table doesn't have a name or ID either, so I'm not sure how i can reference it. – sdailey814 Oct 02 '14 at 20:43
  • 1
    How about using the sibling notation (http://selenium.polteq.com/en/locate-sibling-elements/) – jcfollower Oct 02 '14 at 20:46
  • @jcfollower Was about to say just that. – Silas Ray Oct 02 '14 at 20:49
  • Can one of you help me with the code for this approach? I can locate the "td" two levels up from this "td" by name so I know my code starts with: browser.find_element_by_css_selector("td#B22_1_6 but i'm kind of lost after that, because i am two elements away – sdailey814 Oct 02 '14 at 21:08
  • # is the id selector, if you want to use name, you have to use attribute access. – Silas Ray Oct 02 '14 at 21:10
0

You can do it easily by

driver.find_element(By.XPATH, 'your xpath').click()

For finding the xpath , just inspect the button with firebug, and in html tab right click on selected element and click on Copy XPath.

Hope it will help you.

Juhi Saxena
  • 1,197
  • 11
  • 17