Open and query webpages, manipulate DOM elements and run JavaScript code in a browser.
Start a web session
Use StartWebSession to open a new, empty browser window:
![](Files/ControlAWebBrowserProgrammatically.en/1.png)
- Supported browsers are Chrome and Firefox. If no arguments are given to StartWebSession, it defaults to Chrome.
- Several web sessions can run simultaneously.
Open a webpage
Open a webpage in the browser:
![](Files/ControlAWebBrowserProgrammatically.en/2.png)
- Opening a webpage yields a Success object even when the URL is not a valid destination.
- Web session commands include "PageBack", "ClickElement", "TypeElement", "BrowserWindows" and "SetWindowSize". See the WebExecute documentation for a complete list.
Extract information about the page
Get the webpage title:
![](Files/ControlAWebBrowserProgrammatically.en/3.png)
Get the webpage URL:
![](Files/ControlAWebBrowserProgrammatically.en/4.png)
Get a list of hyperlinks on the webpage:
![](Files/ControlAWebBrowserProgrammatically.en/5.png)
Manipulate the document object model (DOM)
Use the "LocateElements" option to search for elements in the DOM.
Get a reference to the search field on the webpage:
Get a reference to the button on the webpage that initiates a search:
Enter “Ada Lovelace” in the search field, then click the search button:
![](Files/ControlAWebBrowserProgrammatically.en/6.png)
Execute JavaScript code on the page
Pass a block of JavaScript code as a string to WebExecute, and the web driver will execute that code on the live page:
![](Files/ControlAWebBrowserProgrammatically.en/7.png)
End the web session
To end the web session, delete the web session object: