mardi 26 avril 2016

How to submit a form and get DOM updates using JBrowserDriver?

How to submit a form and get DOM updates using JBrowserDriver?

I tried to make the driver wait using so many methods but nothing worked. Am not getting the updated dom at all. I have just replaced my actual url as its confidential. In my case, upon submission, the page data will be changed and the url will remain the same all the time. Then tried to fetch the page data using driver.getPageSource() and also by executing Javascript and tried to fetch the innerHTML of the document object by doing the following. But nothing worked. Can someone help me by posting a working code for fetching the updated page source after form submit using JBrowserDriver?

String updatedPageContent = (String) ((JavascriptExecutor) driver).executeScript("return document.documentElement.innerHTML;");
        System.out.println("Updated Content : " + updatedPageContent);

Here is my code :

Settings settings = Settings .builder() .ajaxResourceTimeout(3000) .ajaxWait(3000) .blockAds(true) .headless(true) .ignoreDialogs(true) .requestHeaders(RequestHeaders.CHROME) .ssl("trustanything") .userAgent(UserAgent.CHROME) .build();

JBrowserDriver driver = new JBrowserDriver(settings);
driver.get("http://www.google.com");
System.out.println("Current Page source : " + driver.getPageSource());
WebElement searchTextBox = (WebElement) ((JavascriptExecutor) driver).executeScript("return document.getElementById('lst-ib');");
searchTextBox.sendKeys("Selenium");
Thread.sleep(1000);
searchTextBox.submit();
Thread.sleep(3000);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
System.out.println("Updated page source : " + driver.getPageSource());
driver.quit();

Note : Instead of submit() method, I even tried to find the button and invoked the click() method, but nothing worked. As you can see in my above code, I tried different types of waits for the driver but in vain. Please help.

Aucun commentaire:

Enregistrer un commentaire