kazurayam said:
Andrew,
You should be aware which technology you are using: CSS selector or XPath.
-----------
You reported the following command succeeded:
document.querySelector("a[href='http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']")
The document.querySelector function accepts a string argument, which is interpreted as a CSS Selector (not as a XPath). See https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
Your string
a[href='http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']
is a valid CSS Selector; it selects element with a href attribute of the specified value.
--------------------
Howerver,
com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Link in the email’ located by ‘By.xpath: //a[href=’http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']'
not found
this messages tells me that you are asking Katalon to interprete your string
a[href='http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']
as a XPath expression. Beware, your string is invalid as a XPath expression. Why invalid? Let me interprete this string as a XPath:
- The root element of your target should be (this is never the case. you should rather write ‘//a’ to seek for in the document)
- You want to select element(s) which has a child element. (this is never the case. in the Hyper Text Markup Languge specificication, there is no element defined.)
- a[href="…"] is not legal as XPath syntax. Rather you may write a[href/text()=’…’], which is syntactically correct, but would select nothing.
-------------------------------------
You have a few choices:
1. Change your Test Obect ‘Link in the email’; of which selector now has ‘xpath’. Change from ‘xpath’ to ‘css’. I mean, you can tell your Test Object ‘Link in the email’ to interprete your string as CSS selector, rather than XPath expression.
or
2. Keep you Test Object ‘Link in the email’ to interprete you string as a xpath expression; and change your string to be a valid XPath expression. I would presume the following string is a valid xpath for you.
//a[@href='http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']
-----------------------------------
If i run this in console it says it is invalid function:
**_$x("//a[@href='http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604’]")
_**Uncaught TypeError: this.oj.apply is not a function
I tried a similar $x() against the GMail page in the Chrome’s DevTool, I encountered Uncaught TypeError as well. I do not know why.
I tried $x tool in the Firefox’ F12 dev tool, and it functioned well.
So you should rather use Firefox instead of Chrome for XPath verification by $x() function
When I open other URLs in Chrome and tried DevTools $x, it functioned OK. Wow. This makes me guess that the GMail page is a very special case for $x. $x seems getting somewhat confused with the GMail page and can not deal with properly.
Hi kazurayam
Actually i have several updates since the last several days.
You are correct with xpath syntax provided and this was my mistake.
Here is what worked (in case someone else needs to address same question):
//a[@href=‘url’]
Here is the exact part of the code:
def EmailPath = new TestObject(“Link in the email”)
def exprURL = data.internallyGetValue(“xPath”, reverse)
EmailPath.addProperty(“xpath”, ConditionType.EQUALS, exprURL)
WebUI.verifyElementPresent(EmailPath, 10, FailureHandling.STOP_ON_FAILURE)
WebUI.click(EmailPath)
I also had to add some logic for the going thru emails sent and order they are arrived.
Not perfect but it works for now. Let me know if you have a better or precise solution.
Problem to Resolve:
Emails sent from the .csv in this order:
- email 1
- email 2
- email **n
**Emails shown in opposite order in the Inbox:
- email n
- email 2
- email 1
I used the same .csv and same loop. Just have 2 variables. One starts from the 1st row of the file and increments all the way to the last record in the file. The other variable works in opposite direction.
Probably trivial for many advance folks here, but i did it by myself and first time.
Thank you for all your guidance!
Andrew