8

For Example:

By.xpath("//*[@id="ext-gen1035"]/div/div[3]/i")
har07
  • 88,338
  • 12
  • 84
  • 137
Prabhu
  • 117
  • 1
  • 3
  • 11
  • 1
    Possible duplicate of [How to escape single quote in xpath 1.0 in selenium for python](http://stackoverflow.com/questions/32759318/how-to-escape-single-quote-in-xpath-1-0-in-selenium-for-python) – Philipp Apr 07 '16 at 16:00
  • Also related : [Appium xpath escaping apostrophes](http://stackoverflow.com/questions/30778287/appium-xpath-escaping-apostrophes/30778431#30778431) – har07 Apr 08 '16 at 00:33

1 Answers1

13

You can actually use single quotes too:

By.xpath("//*[@id='ext-gen1035']/div/div[3]/i")

Or escape double quotes with a backslash:

By.xpath("//*[@id=\"ext-gen1035\"]/div/div[3]/i")
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Escaping with backslashes was apparently (according to https://stackoverflow.com/a/32759467/140707) only introduced in XPath 2.0, which still doesn't have wide adoption. – Frans Feb 23 '22 at 11:25