All Downloads are FREE. Search and download functionalities are using the official Maven repository.

prerna.test.Playwrighter Maven / Gradle / Ivy

The newest version!
package prerna.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.ElementHandle;
import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
import com.microsoft.playwright.BrowserType.LaunchOptions;
import com.microsoft.playwright.options.AriaRole;
import com.microsoft.playwright.options.BrowserChannel;
import com.microsoft.playwright.options.LoadState;

public class Playwrighter implements Runnable
{

	int count = 0;
	public static final String css_id = "pw_id";
	public static final String starter = "You are a natural language to HTML element mapper giving output in the following format as a valid JSON array \n\n [{'pw_id of the element': 'element_value from the prompt provided '}, {'pw_id of the element': 'element_value from the prompt provided '} ] \n\n";
	// by their pw_id attribute that need to be filled. Provide element pw_id and the potential value in the format {'pw_id': 'field pw_id value'}. For html elements provide pw_id attribute of the html element and the potential value from the prompt. Identify all relevant fields that can be pre-filled. Dont identify un-necessary fields. If more than one element provide as an array. 
	public static final String json_format = "Identify the HTML elements that can satisfy the prompt << ";
	//USE THE CONTEXT PROVIDED ONLY. Do NOT manufacture facts. If this page does not allow me to accomplish my goal please respond with {result:NA}. 
	public static final String no_disclaimer = "Be Concise. Do not provide as json markdown. Please provide only VALID. Do not provide introductions, explanations and summary. ";
	List inputList = new ArrayList();
	Map inputLinks = new Hashtable();
	String prompt = null;
	JavaRestClient jrc = null;
	Page cur_page = null;
	int counter = 0;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		/*try (Playwright playwright = Playwright.create()) {
		      Browser browser = playwright.webkit().launch();
		      Page page = browser.newPage();
		      page.navigate("https://playwright.dev/");
		      page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("c:/temp/example.png")));
		    }
		*/
		/*
		String json = "{'out':[{'pw_id=input1': 'newyork'}, {'pw_id=input9': '2024-12-01'}, {'pw_id=input11': '1 day'}, {'pw_id=input14': '1'}, {'pw_id=input15': 'false'}, {'pw_id=input16': 'false'}, {'pw_id=input12': '1'}, {'pw_id=input13': '0'}]}";
		JSONObject obj = new JSONObject(json);
		
		//if(obj instanceof JSONArray)
		{
			System.err.println("Json array");
			
		}
		
		String jsonString = "{\"insightID\":\"684f8817-e41d-4cb2-a9b2-43ff7c1af4e2\",\"pixelReturn\":[{\"pixelId\":\"meta_unstored\",\"pixelExpression\":\"LLM(engine=[\\\"4801422a-5c62-421e-a00c-05c6a9e15de8\\\"], command=[\\\"I would like to travel to newyork for a meeting on december 1. Please provide output as json in the following json format with {pw_id attribute of the element: potential field value}. Try to identify pre-fill for as many fields as possible. Be Concise. Do not provide as markdown. Please provide only the JSON and as valid JSON. Do not provide introductions and summary. If this page does not allow me to accomplish my goal please respond with {result:NA}. --- HTML ELEMENTS FOLLOW -- \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\\"]););\",\"isMeta\":true,\"timeToRun\":-1,\"output\":\"[77,206] expecting: EOF. Error in syntax around attribute of the el\",\"operationType\":[\"ERROR\",\"INVALID_SYNTAX\"]}]}";
		*/
		for(int tIndex = 0;tIndex < 1;tIndex++)
		{
			Playwrighter t = new Playwrighter();
			//t.getOutput(jsonString);
			
			//t.callLLM("hello", null);
			
			t.count = tIndex;
			Thread t1 = new Thread(t);
			System.err.println("Starting thread.. " + tIndex);
			t1.start();
			
		}
		
	}
	
	public void initJRC()
	{
		jrc = new JavaRestClient();
		jrc.login("https://workshop.cfg.deloitte.com/cfg-ai-demo/Monolith/api", "488c161f-ba17-45ba-97a1-22915fb17f15", "43f214d4-c0fa-4587-9d41-438463d77a6d");
		//jrc.login("https://workshop.cfg.deloitte.com/cfg-ai-demo/Monolith/api", "abcd", "xyz");
		//String py = "Py(' 2 + 2')";
		//String llm = "LLM(engine='4801422a-5c62-421e-a00c-05c6a9e15de8', command='hello')";
	}
	
	public void run()
	{
		//runJSoup();
		//runPage();
		//String content = readData("c:/temp/expedia.html");
		
		String baseUrl = "https://play.semoss.org/dev/SemossWeb/";
		prompt = "I would like to travel to newyork for a meeting on december 1 2024 for a day. I am traveling alone. "; 
		prompt = "I would like to login with username: prabhu and password: neelsanghvi";
		//baseUrl = "https://www.expedia.com/";
		baseUrl = "https://www.facebook.com/login";
		//baseUrl = "https://www.kayak.com/";
		//runExpedia();
		//String newContent = convertRelativeToAbsoluteLinks(baseUrl, content);
		//writeData(newContent);
		//baseUrl = "https://www.hotwire.com/";
		//baseUrl = "https://www.makemytrip.com/";
		
		loadPage(baseUrl);
		String finalPrompt = makePrompt();
		initJRC();
		String response = callLLM(finalPrompt, null);
		JSONArray output = getOutput(response);
		System.err.println("Potential Elements ..." + output);
		
		Map outMap = convertJSONArrayToMap(output);
		// get feedback on the elements
		Map setterMap = getUserChoices(outMap);
		
		executePage(setterMap);
		
	}
	
	private String makePrompt()
	{
		// take the basic prompt
		// take the input elements and then convert it into a prompt
		Iterator  keys = inputLinks.keySet().iterator();
		StringBuffer inputMaker = new StringBuffer();
		for(int elemIndex = 0;elemIndex < inputList.size();elemIndex++)
		{
			String key = (String)inputList.get(elemIndex);
			inputMaker.append("   ");
			inputMaker.append(inputLinks.get(key));
		}
		String finalPrompt = starter +json_format + prompt + ">>"  + "--- HTML ELEMENTS START -- " + inputMaker + "--- HTML ELEMENTS END -- " + no_disclaimer;
		System.err.println("---");
		System.err.println(finalPrompt);
		System.err.println("---");
		return finalPrompt;
	}
	
	
	public void loadPage(String baseUrl)
	{
		try
		{
			Playwright pw = Playwright.create();
			Browser context = pw.webkit().launch();
			Page page = context.newPage();
			page.navigate(baseUrl);
			page.waitForLoadState(LoadState.DOMCONTENTLOADED);
			Thread.sleep(3000);
			//page.onDialog(dialog -> dialog.dismiss());
			//page.getByText("Accept").click();
			String content = page.content();
			String title = baseUrl.replace("https://", "").replace("http://", "").replace(".", "_").replace("/", "__");
			content = convertRelativeToAbsoluteLinks(baseUrl, content);
			System.out.println("--------------------");
			FileUtils.write(new File("c:/temp/" + title + ".html"), content);
		    System.err.println("Finished.. ");
		    cur_page= page;
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}
	
	public String callLLM(String finalPrompt, String engineId)
	{
		finalPrompt = finalPrompt.replace("\"", "");
		//finalPrompt = finalPrompt.replace("\'", "");		
		engineId = "4801422a-5c62-421e-a00c-05c6a9e15de8";
		//engineId = "029a1323-db79-415c-be3e-3945438b0808";
		String llm = "LLM(engine=[\"" + engineId + "\"], command=[\"" + finalPrompt + "\"]);";
		System.err.println(llm);
		String response = jrc.runPixel(llm);
		return response;
		/*for(int outputIndex = 0;outputIndex < output.length();outputIndex++)
		{
			JSONObject curObject = output.getJSONObject(outputIndex);
			if(curObject.has(css_id))
			{
				String pw_id = curObject.getString(css_id);
				String pot_value = curObject.getString("potential_value");
				
				
			}	
		}*/
		
		//System.err.println(response);
		
		// extract output
		// get into json
		// see if this is result na
		// if not walk through input elements and replay
	}
	
	private Map getUserChoices(Map llmMap)
	{
		// this is where we get choices from the user
		StringBuffer itemList = new StringBuffer();
		Iterator keys = inputLinks.keySet().iterator();
		while(keys.hasNext())
			itemList.append(keys.next()).append("<>");
		Map newMap = new HashMap();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String elemSelected = null;
		String value = null;
		try {
			do
			{
				System.err.println("Select an Element : " + itemList);
				elemSelected = br.readLine();
				String elemDetails = inputLinks.get(elemSelected).toString();
				System.err.println("Element Details..  " + elemDetails);
				if(llmMap.containsKey(elemSelected))
				{
					value = (String)llmMap.get(elemSelected);
					System.err.println("Proposed Value.. " + value);
				}
				else
					System.err.println("No value proposed.. please enter value");
				value = br.readLine(); // type i for ignore
				if(!value.equalsIgnoreCase("i"))
					newMap.put(elemSelected, value);
				
			}while(!elemSelected.equalsIgnoreCase("i"));
			//while()
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return newMap;
	}
	
	public void executePage(Map valueMap)
	{
		// need to ask the user for button to hit or the link to click
		// set the values and roll
		
		// get the current page
		// set the values
		// click the button
		Iterator  valueKeys = valueMap.keySet().iterator();
		System.err.println("Going to fill " + valueMap.size() + " elements");
		while(valueKeys.hasNext())
		{
			String valueKey = valueKeys.next();
			String value = valueMap.get(valueKey).toString();
			Element elem = (Element)inputLinks.get(valueKey);
			// get the id of this elem ?
			//page.locator("input[name=\"userLoginName\"]").fill("prabhuk");
			String elemName = elem.attr("name");
			if(elemName.length() > 0)
			{
				String selector = "input[name='" + elemName + "']";
				Locator locator = cur_page.locator(selector);
				if(locator != null)
				{
					System.err.println("Found locator.. ");
					locator.fill(value);
				}
			}
		}
		
		// finally click the button
		
	}
	
	private JSONArray getOutput(String jsonString)
	{
		JSONObject obj = new JSONObject(jsonString);
		JSONArray retObject = (JSONArray)obj.get("pixelReturn");
		JSONObject outputObj = retObject.getJSONObject(0);
		JSONObject output = outputObj.getJSONObject("output");
		
		System.err.println(" output.. " + output);
		System.err.println(output.get("response"));
		
		String new_obj = output.get("response") + "";
		new_obj = "{'out': " + new_obj + "}";
		
		JSONObject ret_obj = new JSONObject(new_obj);
		
		return ret_obj.getJSONArray("out");
	}

	
	
	private void replacer(String baseUrl, Elements links, String attr)
	{
		try {
			for (Element link : links) {
			    String href = link.attr(attr);
			    System.err.println("Old Link " + href);
			    if (href.startsWith("/") || href.startsWith("./") || href.startsWith("../") || !href.startsWith("http")) 
			    {
			        URI baseUri = new URI(baseUrl);
			        URI linkUri = new URI(href);
			        URI absoluteUri = baseUri.resolve(linkUri);
			        link.attr(attr, absoluteUri.toString());
				    System.err.println("New Link " + absoluteUri.toString());
			    }
			}
		} catch (URISyntaxException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	
	public String convertRelativeToAbsoluteLinks(String baseUrl, String page)
	{
        // Base URL of the document (you might need to adjust this based on your actual use case)

        // Parse the HTML document
        Document doc;
		try {
			doc = Jsoup.parse(page);

			// Find all links
			Elements links = doc.select("[href]");
			replacer(baseUrl, links, "href");

			// replace all image sources / javascripts
			links = doc.select("[src]");
			replacer(baseUrl, links, "src");
			
			// add events and ids to objects
			// add to the buttons
			links = doc.select("button");
			makeObservable(links, "button", "onclick");
			
			links = doc.select("a");
			//makeObservable(links, "hyper", "onclick");
			
			// put all the inputs
			links = doc.select("input");
			makeObservable(links, "input", "onchange");
			
			// also capture all the links / elements
			//printElements(links);
			links = doc.select("button");
			
			// Convert relative links to absolute
			return doc.html();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

        // Print the updated HTML document
        //System.out.println(doc.html());
		return null;
	}
	
	private void makeObservable(Elements links, String name, String event)
	{
		
		for(int linkIndex = 0;linkIndex < links.size();linkIndex++)
		{
			Element link = links.get(linkIndex);
			link.attr(css_id, name+linkIndex);
			link.attr(event, "alert(document.querySelector('[" + css_id + "=" + name + linkIndex + "]').value)");
			link.removeAttr("disabled");
			String id = link.attr(css_id);
			inputLinks.put(id, link);	
			inputList.add(id);
			
			// get the id and name also
			if(link.hasAttr("id"))
				inputLinks.put(link.attr("id"), link);
			if(link.hasAttr("name"))
				inputLinks.put(link.attr("name"), link);
		}
	}
	
	private Map convertJSONArrayToMap(JSONArray arr)
	{
		
		//{"element_pw_id": "input14", "element_value": "2"},
		Map retMap = new HashMap();
		String keyName = "pw_id";
		String valueName = "value";
		for(int arrIndex =0;arrIndex < arr.length();arrIndex++)
		{
			JSONObject obj = arr.getJSONObject(arrIndex);
			Iterator  objKeys = obj.keys();
			String elemId = null;
			String elemValue = null;
			
			while(objKeys.hasNext())
			{
				String key = objKeys.next();
				String value = obj.get(key) + "";
				
				if(key.contains("="))
					key = key.split("=")[1];

				if(value.contains("="))
					value = value.split("=")[1];

				if(key.contains(css_id))
				{
					if(elemId == null)
					{
						if(inputLinks.containsKey(key))
						{
							elemId = key;
							if(elemValue == null)
								elemValue = value;
						}
						else if(inputLinks.containsKey(value))
							elemId = value;
					}
				}
				else
				   elemValue = value;
					
			}
			retMap.put(elemId, elemValue);
		}
//			if(obj.has(key))
//			{
//				String elemId = obj.getString(key);
//				if(elemId != null && inputLinks.containsKey(elemId) && obj.has(value))
//				{
//					String elemValue = obj.getString(value);
//					retMap.put(elemId, elemValue);
//				}
//			}
//		}
		return retMap;
	}


	
	public void runJSoup(String content)
	{
		try {
			Document doc = null;
			if(content == null)
			{
				String urlLoc = "http://www.semoss.org"; 	
				urlLoc = "https://jsoup.org/cookbook/extracting-data/example-list-links";
				urlLoc = "https://play.semoss.org/dev/SemossWeb/#!/login";
				URL url = new URL(urlLoc);
				
				doc = Jsoup.connect(urlLoc).get();
			}
			else
			{
				doc = Jsoup.parse(content);
			}
			Elements all_els = doc.getAllElements();
			for(int elIndex = 0;elIndex < all_els.size();elIndex++)
			{
				Element ele = all_els.get(elIndex);			
				List  attrs = ele.attributes().asList();
				for(int attrIndex = 0;attrIndex < attrs.size();attrIndex++)
				{
					System.err.println(attrs.get(attrIndex));
				}
				System.err.println(ele.text() + "<>" + ele.html());
			}
			
			
			Elements els = doc.select("a[href]");
			for(int elIndex = 0;elIndex < els.size();elIndex++)
			{
				Element ele = els.get(elIndex);			
				List  attrs = ele.attributes().asList();
				for(int attrIndex = 0;attrIndex < attrs.size();attrIndex++)
				{
					System.err.println(attrs.get(attrIndex));
				}
				System.err.println(ele.attr("href") + "<>" + ele.text() + "<>" + ele.html());
			}

			
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	private String readData(String fileName)
	{
		try {
			return FileUtils.readFileToString(new File(fileName));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	
	private void writeData(String data)
	{
		try {
			FileUtils.write(new File("c:/temp/loginpage2.html"), data);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void runPW()
	{
		try (Playwright playwright = Playwright.create()) {
		      Browser browser = playwright.webkit().launch();
		      Page page = browser.newPage();
		      page.navigate("http://www.gmail.com/");
		      List  allLocs = page.getByRole(AriaRole.TEXTBOX).all();
		      
		      for(int locIndex = 0;locIndex < allLocs.size();locIndex++)
		      {
		    	  Locator thisLoc = allLocs.get(locIndex);
		    	  System.err.println(thisLoc.textContent());
		    	  System.out.println(allLocs.get(locIndex));

		      }
		      Locator loc = page.getByText("DOWNLOAD").first();
		      //Locator loc = page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Download")).first();
		      loc.click();
		      System.err.println(page.content());
		      page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("c:/temp/example" + count + ".png")));
		    }
	}
	
	public void runExpedia()
	{
		
		try (Playwright playwright = Playwright.create())
		{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			
			
			Playwright pw = playwright;
			
		     LaunchOptions lp = new LaunchOptions();
		     lp.setChannel(BrowserChannel.CHROME);
		     lp.setHeadless(false);
		     BrowserType firefox = pw.chromium();
		     Browser context = firefox.launch();
//		      Page page = browser.newPage();

	//		Browser context = pw.webkit().launch();
			Page page = context.newPage();
			String baseUrl = "https://www.hotwire.com/";
			//baseUrl = "https://ecommerce-playground.lambdatest.io/";
			page.navigate(baseUrl);
			Thread.sleep(2000);
			String data = null;
			System.err.println("Enter locator");
			do
			{
				Locator where = null;
				/*
				practice
				where = page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Search"));
				System.err.println(where.getAttribute("class"));
				 */
				//where.get
				//data-stid="destination_form_field-menu-trigger"
				//where = page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Where to?"));
				String locator = "//*[@data-stid=\"destination_form_field-menu-trigger\"]";
				String selector = "Where would you like to stay?";
				String selector2 = "//*[@id=\"lodging_search_form\"]/div/div/div[1]/div/div/div[1]/button";
				//selector = "pierce/#lodging_search_form > div > div > div:nth-of-type(1) button";
				where = page.getByPlaceholder(selector);
				where.fill("WAS");
				//where.click();
				//where.press("Enter");
			
				where.press("ArrowDown");
				where.press("Enter");
				where.press("Escape");
				//page.locator(".farefinder-container").click();
				Thread.sleep(1000);
				//page.keyboard().
				
				//ElementHandle handle = page.querySelector(selector);
				//handle.click();
				//Thread.sleep(1000);
				//handle = page.querySelector(selector2);
				//System.err.println("Found it.. " + where.getAttribute("class"));
				//where = page.locator(locator);
				Locator search = page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Find a hotel"));
				System.err.println("Visibility.. " + search.isVisible() + search.isEnabled());
				//where.vi
				search.click();
				//while (where.isVisible())
				//	where.click();
				Thread.sleep(3000);
			    page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("c:/temp/example" + count + ".png")));
			    FileUtils.write(new File("c:/temp/popup.html"), page.content());
			    
			    
			    
			}while((data = br.readLine()) != null);

			//page.onDialog(dialog -> dialog.dismiss());
			//page.getByText("Accept").click();
			Locator where = page.locator("button[data-stid=\"destination_form_field-menu-trigger\"]");
			where.click();
			System.err.println("clicked where to");
			Thread.sleep(2000);
			// this is where I need to get to the locator handler
		    where.locator("input[data-stid=\"destination_form_field-dialog-input\"]").fill("WAS");
		    page.locator("input[data-stid=\"destination_form_field-dialog-input\"]").press("Enter");
			Thread.sleep(3000);
		    page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("c:/temp/example" + count + ".png")));
		    
			//page.locator("input[name=\"userLoginName\"]").fill("prabhuk");
			//page.locator("input[name=\"userLoginPassword\"]").fill("S3m0ss!23");
			
			
			//runJSoup(content);
			//System.err.println(page.content());
			
			/*List locList = page.querySelectorAll(" ");
			for(int locIndex = 0;locIndex< locList.size();locIndex++)
			{
				ElementHandle thisElement = locList.get(locIndex);
				System.err.println(thisElement.textContent());
			}*/
			//cookie.getByLabel("Accept").click();
			//System.err.println(page.getByText(("Notice:")));

			// gets all the popups.. 
			/*page.onPopup(popup -> {
				  popup.waitForLoadState();
				  System.out.println(popup.title());
				});
			*/
			
			
			//Page popup = page.waitForPopup(() -> {page.getByText("open the popup").click();});
			//popup.getByRole(AriaRole.BUTTON).click();
			
			//page.waitForLoadState();
			
			/*
			// Interact with login form
			page.locator("input[name=\"userLoginName\"]").fill("prabhuk");
			page.locator("input[name=\"userLoginPassword\"]").fill("S3m0ss!23");
			page.getByRole(AriaRole.BUTTON,
		         new Page.GetByRoleOptions().setName("Log In").setExact(true)).click();
			// Pattern.compile("Log In", Pattern.CASE_INSENSITIVE))
			Thread.sleep(3000);
			//page.wait(3000);
			//page.navigate("https://play.semoss.org/dev/SemossWeb/#!/");
			System.err.println("Finished fill");
			//List  locators = page.getByRole(AriaRole.FORM).all();
			//System.err.println(locators.size());
			//page.waitForSelector("input[type="username"]", { visible: true });
			//page.getByLabel("Password").fill("S3m0ss!23");
			//page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Log in")).click();			
			//FileWriter fw = new FileWriter(new StringWriter());
			content = page.content();
			content = convertRelativeToAbsoluteLinks(baseUrl, content);
			FileUtils.write(new File("c:/temp/semosspage.html"), content);
		    page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("c:/temp/example" + count + ".png")));
		    */
		    System.err.println("Finished.. ");
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}
	
	public void runPage()
	{
		try
		{
			Playwright pw = Playwright.create();
			Browser context = pw.webkit().launch();
			Page page = context.newPage();
			String baseUrl = "https://play.semoss.org/dev/SemossWeb/";
			page.navigate("https://play.semoss.org/dev/SemossWeb/#!/login");
			page.onDialog(dialog -> dialog.dismiss());
			page.getByText("Accept").click();
			String content = page.content();
			content = convertRelativeToAbsoluteLinks(baseUrl, content);
			System.out.println("--------------------");
			FileUtils.write(new File("c:/temp/loginpage.html"), content);

			//runJSoup(content);
			//System.err.println(page.content());
			
			/*List locList = page.querySelectorAll(" ");
			for(int locIndex = 0;locIndex< locList.size();locIndex++)
			{
				ElementHandle thisElement = locList.get(locIndex);
				System.err.println(thisElement.textContent());
			}*/
			//cookie.getByLabel("Accept").click();
			//System.err.println(page.getByText(("Notice:")));

			// gets all the popups.. 
			/*page.onPopup(popup -> {
				  popup.waitForLoadState();
				  System.out.println(popup.title());
				});
			*/
			
			
			//Page popup = page.waitForPopup(() -> {page.getByText("open the popup").click();});
			//popup.getByRole(AriaRole.BUTTON).click();
			
			//page.waitForLoadState();
			
			/*
			// Interact with login form
			page.locator("input[name=\"userLoginName\"]").fill("prabhuk");
			page.locator("input[name=\"userLoginPassword\"]").fill("S3m0ss!23");
			page.getByRole(AriaRole.BUTTON,
		         new Page.GetByRoleOptions().setName("Log In").setExact(true)).click();
			// Pattern.compile("Log In", Pattern.CASE_INSENSITIVE))
			Thread.sleep(3000);
			//page.wait(3000);
			//page.navigate("https://play.semoss.org/dev/SemossWeb/#!/");
			System.err.println("Finished fill");
			//List  locators = page.getByRole(AriaRole.FORM).all();
			//System.err.println(locators.size());
			//page.waitForSelector("input[type="username"]", { visible: true });
			//page.getByLabel("Password").fill("S3m0ss!23");
			//page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Log in")).click();			
			//FileWriter fw = new FileWriter(new StringWriter());
			content = page.content();
			content = convertRelativeToAbsoluteLinks(baseUrl, content);
			FileUtils.write(new File("c:/temp/semosspage.html"), content);
		    page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("c:/temp/example" + count + ".png")));
		    */
		    System.err.println("Finished.. ");
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}



}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy