fix 6: Selectors - text

This commit is contained in:
Sami 2024-11-06 13:00:01 -05:00
parent 2235e1bb69
commit 6b7d95a461
2 changed files with 42 additions and 0 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 75 KiB

View File

@ -0,0 +1,42 @@
package zacksolutions;
import com.microsoft.playwright.*;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.nio.file.Paths;
public class TextSelectorTest {
Playwright playwright;
Browser browser;
Page page;
@BeforeTest
public void setUp(){
playwright = Playwright.create();
browser = playwright.firefox().launch(new BrowserType.LaunchOptions().setHeadless(false));
page = browser.newPage();
}
@Test
public void browserLaunch() {
page.navigate("https://amazon.com");
System.out.println(page.title());
Locator linkCount = page.locator("text=Amazon");
System.out.println(linkCount.count());
for (int i = 0; i < linkCount.count(); i++) {
String text = linkCount.nth(i).textContent();
if(text.contains("Science")){
System.out.println(text);
linkCount.nth(i).click();
break;
}
}
}
@AfterTest
public void tearDown() {
/*
browser.close();
playwright.close();
*/
}
}