Skip to main content
Version: 10.2.8

Automate browser navigation commands

TypeMethodDescription
voidback()
  • Browser: Move back a single item in the browser's history.
  • Desktop: Move back to the preview window in the desktop driver history.
voidforward()
  • Browser: Move a single item forward in the browser's history. Does nothing if you are on the latest page viewed.
  • Desktop: Move forward to the next window in the desktop driver history.
void
  • driver().navigate().to(java.lang.String url)
  • driver().navigate().to(java.net.URL url)
  • Browser: Load a new web page in the current browser window. This is done using an HTTP GET operation, and the method blocks until the load is complete. This follows redirects issued either by the server or as a meta-redirect from within the returned HTML. Should a meta-redirect rest for any duration of time, it is best to wait until the timeout is over, since the underlying page should change while your test is executing the results of future calls against this interface will be against the freshly loaded page.
  • Desktop: Run a program.
voidrefresh()
  • Browser: Refresh the current page.
  • Desktop: Empty the implementation.

The sample below:

  1. Opens the documentation main page.
  2. Navigates to a new page by clicking a link.
  3. Navigates back to the documentation main page.
  4. Navigates forward to the Release Notes page.
  5. Opens the Wikipedia website in the current tab.
  6. Refreshes the current page.
Expand to view code
import com.workfusion.odf2.compiler.BotTask;
import com.workfusion.odf2.core.task.AdHocTask;
import com.workfusion.odf2.core.task.TaskInput;
import com.workfusion.odf2.core.task.output.TaskRunnerOutput;
import com.workfusion.odf2.core.webharvest.rpa.RpaDriver;
import com.workfusion.odf2.core.webharvest.rpa.RpaFactory;
import com.workfusion.odf2.core.webharvest.rpa.RpaRunner;
import com.workfusion.rpa.driver.Driver;
import com.workfusion.rpa.helpers.RPA;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;

import javax.inject.Inject;

@BotTask(requireRpa = true)
public class BrowserNavigationCommand implements AdHocTask {

private final RpaRunner rpaRunner;
private final Logger logger;

@Inject
public BrowserNavigationCommand(RpaFactory rpaFactory, Logger logger){
this.rpaRunner = rpaFactory
.builder(RpaDriver.UNIVERSAL)
.closeOnCompletion(true)
.build();
this.logger = logger;
}

@Override
public TaskRunnerOutput run(TaskInput taskInput) {

rpaRunner.execute(driver ->{

RPA.timeouts(40 * 1000);
//kindly provide your username and password if asked for
RPA.openChrome("https://doc.workfusion.com/platform/");
this.popAlert(driver,"Kindly enter your Academy username and password");


WebElement releaseNoteLink = driver.findElementByPartialLinkText("notes");
this.popAlert(driver,"Clicking on Release Notes");
releaseNoteLink.click();
RPA.sleep(2000);

this.popAlert(driver,"Switching back to Overview page");
RPA.back();
RPA.sleep(2000);

this.popAlert(driver,"Forwarding to Release Note page");
RPA.forward();
RPA.sleep(2000);

this.popAlert(driver,"Opening Wikipedia.com");
driver.navigate().to("https://www.wikipedia.org/");
RPA.sleep(2000);

this.popAlert(driver,"Refreshing the web page");
RPA.refresh();
RPA.sleep(2000);

});

return taskInput.asResult()
.withColumn("example_bot_task_output", "completed_successfully");
}

private void popAlert(Driver driver,String popupMessage){

driver.switchDriver("chrome");
//Switch to default content inorder to work with alert if already on a IFrame
RPA.switchTo().defaultContent();
String script = popupMessage;
driver.executeScript("alert(arguments[0])",script);
RPA.sleep(3000);
RPA.switchTo().alert().accept();

}
}