Selenium with Python: how to click preceding element -
I am working with a calendar and the only element that I can access (due to non-interrogated issues) There is a button saying 'Today' on top of it On the left side there is a left arrow that takes you back in a month; Similarly, there is a right arrow on the right hand side which moves you one month forward. The HTML looks like this:
& lt; Tr style = "- moz-user-select: none;" & Gt; & Lt; Td square = "button nav" style = "- mozzy-user-selection: none;" Colons = "1" & gt; «& Lt; / Td> & Lt; Td square = "button nav" style = "- mozzy-user-selection: none;" Colons = "1" & gt; <& Lt; / Td> & Lt; Td square = "button nav" style = "- mozzy-user-selection: none;" Callspan = "3" & gt; Today & lt; / Td> & Lt; Td square = "button nav" style = "- mozzy-user-selection: none;" Colons = "1" & gt; > & Lt; / Td> & Lt; Td square = "button nav" style = "- mozzy-user-selection: none;" Colons = "1" & gt; »& Lt; / Td> & Lt; / TR & gt; I can click on the button using 'Today':
driver.find_element_by_xpath ("// td [text () = 'today '] "). Click () In addition, I can click on the right arrow using 'following':
driver.find_element_by_xpath ("// Td [text () ============================================= ================================================== ======= I This is what I am trying to say .. It says that it can not find element with xpath == //.../ p> driver .find_element_by_xpath ("// td [text () = 'today'] / predecessor :: TD". ()
Do another one to find the previous element / brother Use the command
If it matters, then I am using IE9 and Selenium 2.44.
Thanks.
Try the following xpaths:
1 - Click the & lt; Arrow :
// td [in (text (), 'today')] / predecessor- sibling :: td [1] < P> The first "td" element on top of the xpath has been inserted into the "TD" element in which the internal HTML / text is "Today" 2 - "& lt;
// td [in (text (), 'today')] / predecessor- sibling :: td [2] Add another "td" element to the "TD" element on the exapath, in which the internal HTML / text is "Today" .
Comments
Post a Comment