Function to click on link using xpath
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Function to click on link using xpath
I am trying to write a simple function to click on a link using the xpath to the link. I am getting a runtime error on the browser.Page.FindElement - can you please point me in the right direction. Many thanks.
function selectApplyPermitLink()
{
let browser = Aliases.browser;
page = browser.Page("*");
//I would like to have the code use the xpath shown below to click on the link..
browser.Page.FindElement("//a[.='Apply for a permit']").Click();
}
Solved! Go to Solution.
- Labels:
-
Script Tests
-
Web Testing
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you record your actions, then convert the test to scripts. You will then see the actual code the TC has generated.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for you response. Yes... I did record it, but even this code does not work when run (see below). Also I am trying to build a framework using xpath, rather than record and playback.
function Test1()
{
Browsers.Item(btEdge).Navigate("https://blah-qa.powerappsportals.com/");
let browser = Aliases.browser;
browser.BrowserWindow.Maximize();
browser.pageFilmPermitHomePageCustomPort.linkApplyForAPermit.Click();
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you try something like this (see Page Object),
function Example()
{
Browsers.Item(btEdge).Run("http://smartbear.com/");
var page = Sys.Browser(btEdge).Page("*");
page.FindElement("//a[.='Apply for a permit']").Click();
}
Change the URL; use either Find() or FindElement().
Note, I only suggested the record actions, so that you can see the script that TC generates - to see the XPath query.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much. It works.
