-1

I'm trying to find the element by xpath and constantly getting syntax error

It puts ^ mark before the colon in my xpath.

I'm generating the xpath in Chrome dev tools. Finding the element in html, right clicking it and selecting Copy xpath.

C:\>python ebcm_login.py
  File "ebcm_login.py", line 47
    elem = driver.find_element_by_xpath("//*[@id="j_idt51:j_idt55_body"]/table/tbody/tr/td[2]/table/tbody/tr[6]/td[1]/input")
                                                        ^
SyntaxError: invalid syntax

C:\>python ebcm_login.py
  File "ebcm_login.py", line 48
    elem = driver.find_element_by_xpath("//*[@id="menuForm:j_idt57"]/table/tbody/tr/td[2]")
                                                         ^
SyntaxError: invalid syntax

C:\>python
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
fredtantini
  • 15,966
  • 8
  • 49
  • 55
obanawev
  • 19
  • 1
  • 6

1 Answers1

0

try using

elem = driver.find_element_by_xpath('//[@id="j_idt51:j_idt55_body"]/table/tbody/tr/td[2]/table/tbody/tr[6]/td[1]/input')

You are having overlapping quotation marks there. You're probably confusing it. Here in your example you have placed double quotes inside existing double quotes.

for eg: '"obanawev"' is valid similarly "'obanawev'" is also valid but not ""obanawev""

You can even give it inside triple quotes. Then you can use both double and single quote and overlapping of quotation marks can be avoided.

for e.g.:

elem = driver.find_element_by_xpath("""//[@id="j_idt51:j_idt55_body"]/table/tbody/tr/td[2]/table/tbody/tr[6]/td[1]/input""")
Vipul
  • 4,038
  • 9
  • 32
  • 56