({{, (RefLink[WebExecute, paclet:ref/WebExecute])[cmd] 
executes the command cmd in a web browser. }, {, (RefLink[WebExecute, paclet:ref/WebExecute])[{(Subscript[cmd, 1]),(Subscript[cmd, 2]),…}]
executes a list of commands in sequence.}, {, (RefLink[WebExecute, paclet:ref/WebExecute])[session,cmds] 
executes cmds in the specified web session.}})

OpenersNotesSection(Spacer1)Details

(RefLink[WebExecute, paclet:ref/WebExecute]) executes commands in a web browser through a web driver.

If a web session has been started with (RefLink[StartWebSession, paclet:ref/StartWebSession]), (RefLink[WebExecute, paclet:ref/WebExecute])[cmds] executes commands in that session, as specified by (RefLink[$CurrentWebSession, paclet:ref/$CurrentWebSession]).

If no web session has been started, (RefLink[WebExecute, paclet:ref/WebExecute])[cmds] starts a web session, executes cmds, then ends the web session.

(RefLink[WebExecute, paclet:ref/WebExecute])[cmd] returns either the output of the command or a (RefLink[Success, paclet:ref/Success]) or (RefLink[Failure, paclet:ref/Failure]) object.

(RefLink[WebExecute, paclet:ref/WebExecute])[{(Subscript[cmd, 1]),(Subscript[cmd, 2]),…}] returns a list of the results for the (Subscript[cmd, i]).

Commands in (RefLink[WebExecute, paclet:ref/WebExecute]) are typically specified in the following forms:

(RefLink[WebExecute, paclet:ref/WebExecute]) supports the following commands related to complete webpages:

(RefLink[WebExecute, paclet:ref/WebExecute]) supports the following commands related to elements of webpages:

Elements of webpages can be specified in any of the following forms:

(RefLink[WebExecute, paclet:ref/WebExecute]) supports the following commands related to windows:

(RefLink[WebExecute, paclet:ref/WebExecute]) allows the following general commands:

(RefLink[WebExecute, paclet:ref/WebExecute]) uses the protocol defined by W3C.

OpenersPrimaryExamplesSection(Spacer1)Examples  (8)

OpenersExampleSection0(Spacer1)Basic Examples  (5)

Start a web session:

session=StartWebSession[]

Open a webpage in the current session:

WebExecute["OpenPage"->"https://www.wolfram.com"]

Close the session:

DeleteObject[session]

Start a web session:

session=StartWebSession[]

Open a webpage:

WebExecute[session,"OpenPage"->"https://en.wikipedia.org/wiki/The_Example"]

Get the URL of the page open in the browser:

WebExecute[session,"PageURL"]

Go back to the previous page in the browser tab’s history:

WebExecute[session,"PageBack"]

Go one page forward in the browser tab’s history:

WebExecute[session,"PageForward"]

Refresh the page:

WebExecute[session,"RefreshPage"]

Get the title of the page open in the browser:

WebExecute[session,"PageTitle"]

Get hyperlinks on the page open in the browser:

WebExecute["PageHyperlinks"]//Short

Close the current web session:

DeleteObject[session]

Run multiple commands in a single command:

WebExecute[{
"OpenPage"->"https://www.wolfram.com",
"PageTitle",
"OpenPage"->"https://www.wolframalpha.com",
"PageTitle",
"OpenPage"->"https://www.wolframcloud.com",
"PageTitle"
}][[{2,4,6}]]//Column

Start a web session:

session=StartWebSession[]

Open a webpage in the current session:

WebExecute[session,"OpenPage"->"https://en.wikipedia.org/wiki/Example"]

Locate header elements on the page using "LocateElements":

headers=WebExecute[session,"LocateElements"->"Tag"->"h2"]

Find the element text of the HTML headers found previously:

WebExecute["ElementText"->headers]

Find paragraphs of text on a webpage with "XPath":

WebExecute["ElementText"->"XPath"->"//*/p"]

Close the session:

DeleteObject[session]

Start a web session:

session=StartWebSession[]

Open a webpage in the current session:

WebExecute[session,"OpenPage"->"https://www.wolframalpha.com"]

Find the search input box using "LocateElements" with "CSSSelector":

input =  WebExecute[session, "LocateElements"->"CSSSelector"->"#query"]//First

Use "TypeElement" to type into the search box found previously:

WebExecute[session, "TypeElement"->{input, "photon"}]

Submit the form with the query:

WebExecute[session, "SubmitElement"->input]

Check the page URL to see that the query was submitted:

WebExecute[session, "PageURL"]

Close the session:

DeleteObject[session]

OpenersExampleSection1(Spacer1)Scope  (3)

Start a web session:

session=StartWebSession[]

Open a webpage:

WebExecute[session,"OpenPage"->"https://en.wikipedia.org/wiki/The_Example"]

Get all the elements for the <a> (hyperlink) tag:

e=WebExecute["LocateElements"->"Tag"->"a"];

Click a randomly chosen hyperlink:

WebExecute["ClickElement"->RandomChoice[e]]

Get the title of the page:

WebExecute["PageTitle"]

Close the session:

DeleteObject[session]

Start a web session:

session=StartWebSession[]

Open a webpage:

WebExecute["OpenPage"->"https://en.wikipedia.org/wiki/The_Example"]

Get all the elements for the <p> (paragraph) tag:

e=WebExecute["LocateElements"->"Tag"->"p"];

Hide all the paragraphs of text on the page:

Scan[WebExecute["HideElement"->#]&,e]

All text paragraphs are now hidden:

WebExecute["CapturePage"]

Show the text paragraphs again:

Scan[WebExecute["ShowElement"->#]&,e]

The text has reappeared on the page:

WebExecute["CapturePage"]

Close the session:

DeleteObject[session]

Start a web session:

session = StartWebSession[]

Use (RefLink[WebExecute, paclet:ref/WebExecute]) to open to a new page:

WebExecute["OpenPage"->"https://www.wolfram.com"]

Use (RefLink[WebExecute, paclet:ref/WebExecute]) to open a new browser tab:

WebExecute["JavascriptExecute"->"window.open('https://www.wolframalpha.com', '_blank')"]

Use (RefLink[WebExecute, paclet:ref/WebExecute]) to get the open windows:

windows = WebExecute["BrowserWindows"]

Use (RefLink[WebExecute, paclet:ref/WebExecute]) to get the title of the first page:

WebExecute["PageTitle"]

Use (RefLink[WebExecute, paclet:ref/WebExecute]) to switch to the second window:

WebExecute["SetBrowserWindow"-> windows[[2]]]

Use (RefLink[WebExecute, paclet:ref/WebExecute]) to get the title of the second page:

WebExecute["PageTitle"]

Delete the session with (RefLink[DeleteObject, paclet:ref/DeleteObject]):

DeleteObject[session]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[WebImage, paclet:ref/WebImage])  ▪  (RefLink[StartWebSession, paclet:ref/StartWebSession])  ▪  (RefLink[WebSessionObject, paclet:ref/WebSessionObject])  ▪  (RefLink[WebElementObject, paclet:ref/WebElementObject])  ▪  (RefLink[WebWindowObject, paclet:ref/WebWindowObject])  ▪  (RefLink[URLExecute, paclet:ref/URLExecute])  ▪  (RefLink[Import, paclet:ref/Import])  ▪  (RefLink[ServiceExecute, paclet:ref/ServiceExecute])  ▪  (RefLink[ExternalEvaluate, paclet:ref/ExternalEvaluate])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Web Operations, paclet:guide/WebOperations])}, {▪(RefLinkPlain[Web Browser Automation, paclet:guide/WebBrowserAutomation])}, {▪(RefLinkPlain[Importing and Exporting, paclet:guide/ImportingAndExporting])}, {▪(RefLinkPlain[HTTP Requests & Responses, paclet:guide/HTTPRequestsAndResponses])}, {▪(RefLinkPlain[Tuning & Debugging, paclet:guide/TuningAndDebugging])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(Spacer1)▪(WebLink[(Spacer1)W3C standard for CSS selector patterns, https://www.w3.org/TR/selectors-3/])}, {(Spacer1)▪(WebLink[(Spacer1)W3C standard for XML Path Language (XPath), https://www.w3.org/TR/xpath-3/])}, {(Spacer1)▪(WebLink[(Spacer1)W3C standard for webdriver protocol, https://www.w3.org/TR/xpath-3/])}})}})