fix 6: Selectors - text
This commit is contained in:
parent
2235e1bb69
commit
6b7d95a461
Binary file not shown.
|
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 75 KiB |
42
Playright/src/test/java/zacksolutions/TextSelectorTest.java
Normal file
42
Playright/src/test/java/zacksolutions/TextSelectorTest.java
Normal 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();
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user