1

i am new in Selenium trying to click() in selenium Webdriver but it's not work
i use Firebug and Firepath in Firefox to help me find xpath
i enter this xpath into firepath Firefox, it's highlight all element i want, but not click()
this is my code

browser.find_elements_by_xpath('//td[@zoneid="A1"]/div').click()

this is page source

<td class="seatSample">
<td id=“C_1" class="seatItem" title=“available” price=“35.0" zoneid="A1" seatname=“C1" style="background-color:#33b093 ;">
<div style=“width:20px;">1</div>
</td>
<td id=“C_2" class="seatItem" title="available" price=“35.0" zoneid="A1" seatname=“C2" style="background-color:#33b093 ;">
<div style=“width:20px;">2</div>
</td>

Any help is appreciated.

meowmeow
  • 13
  • 4

1 Answers1

0

try as follows:

to click the element with text 1:

 browser.find_element_by_xpath('//td[@zoneid="A1"]/div[text()="1"]').click()

to click the element with text 2:

 browser.find_element_by_xpath('//td[@zoneid="A1"]/div[text()="2"]').click()
Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65
  • use `find_element_by_xpath` not `find_elements_by_xpath` – Naveen Kumar R B Dec 16 '16 at 07:42
  • ohh sorry my bad, i try error **Message: no such element: Unable to locate element: {"method":"xpath","selector":"//td[@zoneid="A1"]/div[text()="1"]"}** – meowmeow Dec 16 '16 at 07:46
  • check whether the element is inside a frame. if your element is inside an iframe tag (look complete hierarchy from the element to `html` tag and check whether `iframe` tag is present as a parent), then first you switch to the frame and then find the element inside of it. my detailed answer is here http://stackoverflow.com/a/40759300/2575259 – Naveen Kumar R B Dec 16 '16 at 08:14
  • your help so awesome, work Perfectly! i need to switch to iframe before click() **browser.switch_to_frame(browser.find_element_by_name("iFrameName"))** – meowmeow Dec 16 '16 at 08:37
  • Thanks you very much, Naveen – meowmeow Dec 16 '16 at 08:38