Home > Automation Testing > Identify dynamic link or webElement using Protractor

Identify dynamic link or webElement using Protractor

If the text of link/webElement is continuously changing then we call it as dynamic link or web element. We have two scenarios, first scenario is text of link may completely change second scenario is text of link may partially change. If it is partially changing we can use locator partailLinkText for links and contains function in xpath for other than link. If the text is completely changing we can go for other parameters of web element. Sometimes no parameter is unique in this case we can go for independent-dependent xpath.

Create specification file with name clickOnLink.js. Write the code to open google.com. Enter search text in search box. Click on search button. Find the relevant website in search results and click on it.

  • In “describe” block we need to mention test case description. In “it” block we need to mention test step description. We can have multiple “it” blocks inside one describe block. And we can have “describe” block inside “describe” block.
  • In first two lines of code we are increasing “jasmine.DEFAULT_TIMEOUT_INTERVAL” because by default it is set to 10000 milliseconds. If complete test step is taking more than default it will fail with error “Error: Timeout – Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL”. To avoid this failure we should increase it.
  • In third line of code we are making waitForAngularEnabled as false. Protractor can be used for both angular and non angular applications. If we using protractor for non angular web application we need to make it as false. If it is angular application we need to mention it as true. It helps to wait for angular web elements implicitly.
  • To open the browser we need to use get(URL); function.
  • We have defined implicit wait which will wait for all web elements.
  • In sixth line we are maximizing the browser.
  • In seventh line we are identifying the google search box using ID and entering value using sendKeys() function.
  • And then identifying google search button using xpath and performing click operation on it.
  • In last line identifying our website using xpath and clicking on it.
  • If the URL is dynamic. For example it may display in formats “www.societyhive.com” or “https://www.societyhive.com/” then we can use contains method in xpath.
  • If the web element is a link(having tag as ‘a’) and its text is partially changing then we can use locator “partialLinkText”.
This Article is TAGGED in , , . BOOKMARK THE permalink.

Avatar photo
Amit Bharamasali
Automation Software Test Engineer. Skills: Manual Testing, Selenium, Java, Protractor, JavaScript, Katalon Studio, Groovy, Appium, Sahi, Sahi Script and UI/UX testing.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">