Automate browser navigation commands
| Type | Method | Description |
|---|---|---|
void | back() |
|
void | forward() |
|
void |
|
|
void | refresh() |
|
The sample below:
- Opens the documentation main page.
- Navigates to a new page by clicking a link.
- Navigates back to the documentation main page.
- Navigates forward to the Release Notes page.
- Opens the Wikipedia website in the current tab.
- 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();
}
}