Autohotkey-Selenium Question: How to escape the Apostrophe (') character for a element that contains a text with it? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Renets
Posts: 36
Joined: 12 Jul 2018, 13:11

Autohotkey-Selenium Question: How to escape the Apostrophe (') character for a element that contains a text with it?

04 Jun 2020, 14:39

I've tried many options, like in this links
https://stackoverflow.com/questions/39601090/escape-apostrophe-in-selenium
https://stackoverflow.com/questions/37542773/how-to-use-apostrophe-in-xpath-while-finding-element-using-webdriver
https://developers.perfectomobile.com/display/TT/Eclipse+-+Auto-Escape+Quotes+While+Pasting+Xpath

But none work, my objective is to pinpoint (to be able to do click later) an element that contains the text:
Senua's Saga: Hellblade2
The element looks like this in HTML

Code: Select all

<span class="01732d6d
ik7dh3pa d2edcug@ qv6é6swib
cletSuq] a8c37x1j s89635nw
ew@dbkib a5q79mjw gicxx5fr
ekzkrbhg oo9gr5id hzawbc8m
dir="auto">Senua's Saga:
Hellblade 2?</span> 
The thing is because it have that (') in the string, it causes error while running the script, it, more specifically:
invalid selector: Unable to locate an element with the xpath expression
This works, but because I trimmed the whole string

Code: Select all

MsgBox % oChrome.findElementByXpath("//*[contains(text(),'Hellblade 2')]").Attribute("outerHTML")
And this doesn't work, which is my ideal objective

Code: Select all

MsgBox %  oChrome.findElementByXpath("//*[contains(text(),'Senua's Saga: Hellblade 2')]").Attribute("outerHTML")
I've tried things like

Code: Select all

MsgBox %  oChrome.findElementByXpath("//*[contains(text(),\""Senua's Saga: Hellblade 2\"")]").Attribute("outerHTML")
But doesn't work either
Any suggestions? Thanks!
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Autohotkey-Selenium Question: How to escape the Apostrophe (') character for a element that contains a text with it?

04 Jun 2020, 17:17

MsgBox % oChrome.findElementByXpath("//*[contains(text(),`'Senua`'s Saga: Hellblade 2`')]").Attribute("outerHTML")
Will this do it (it is using backticks to escape its following character)?
Renets
Posts: 36
Joined: 12 Jul 2018, 13:11

Re: Autohotkey-Selenium Question: How to escape the Apostrophe (') character for a element that contains a text with it?

04 Jun 2020, 17:29

BoBo wrote:
04 Jun 2020, 17:17
MsgBox % oChrome.findElementByXpath("//*[contains(text(),`'Senua`'s Saga: Hellblade 2`')]").Attribute("outerHTML")
Will this do it (it is using backticks to escape its following character)?
Didn't work, it throws the same error :(
Renets
Posts: 36
Joined: 12 Jul 2018, 13:11

Re: Autohotkey-Selenium Question: How to escape the Apostrophe (') character for a element that contains a text with it?  Topic is solved

04 Jun 2020, 18:31

Sooo, at the end it was so obvious! but got scrambled with the research!

This works:

Code: Select all

MsgBox % oChrome.findElementByXpath("//*[contains(text(),""Senua's Saga: Hellblade 2"")]").Attribute("outerHTML")

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 385 guests