How to Automate Links On Page using Playwright Java
1.Print All link on the page
2.Block of the page link to be print
package com.example.pr;
import com.microsoft.playwright.*;
public class LinksExample {
public static void main(String[] args) throws InterruptedException {
Playwright playwright = Playwright.create();
Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions()
.setHeadless(false)
.setChannel("chrome")
);
Page page = browser.newPage();
page.navigate("https://ultimateqa.com/automation");
Locator pagelinks = page.locator("a");
System.out.println("Total link on page ---"+ pagelinks.count());
for(int i =0 ; i < pagelinks.count(); i++){
System.out.println(pagelinks.nth(i).innerText()+" Print HREF attribute associated to Links =="+ pagelinks.nth(i).getAttribute("href"));
}
// Get Block /Area of the page link to print
System.out.println("======================================");
Locator pageBlock = page.locator(".et_pb_section.et_pb_section_1.et_pb_with_background.et_section_specialty");
Locator pageBlockLink = pageBlock.locator("a");
for(int i =0 ; i < pageBlockLink.count(); i++){
System.out.println(pageBlockLink.nth(i).innerText()+" Print HREF attribute associated to Links =="+ pageBlockLink.nth(i).getAttribute("href"));
}
}
}
Comments
Post a Comment