Browser Selenium
Browser automation allows users to interact directly with web applications using browser actions. Web element is a frequently used attribute in the configuration process, equivalent to html tag, which identifies the location of an element in a web page by setting the Element locator value.
Browser automation is commonly used in the following processes:
- Capture web page data and store it in the database.
- Fill out complex forms on web pages and save them to automate the ordering of a business process.
- Document upload and download operations.
- Take screenshots of entire and partial areas of web pages.
Configure Browser
Currently browser automation only works with Google Chrome, so you need to make sure you have Google Chrome installed correctly.
Element locator
A string expression used to locate and identify elements on a web page can usually be represented as XPath. The following are the exact steps to get the XPath of a web page element:
Step 1: Developer Tools
Open Chrome and select "More Tools" > "Developer Tools"
Step 2: Select and copy XPath
a. Open the url https://finance.yahoo.com/
.
b. Inspect the search box element in the page.
c. Select Copy XPath / full XPath
on the inspected search box.
Actions
Open
Open a browser and navigate to the specified site.
- Browser: Selects the browser type:
- Google Chrome
- Chrome Portable
- URL to open: the URL to navigate to.
- Timeout after seconds: Set the timeout seconds after loading page.
- Undetected mode: Enable the anti-crawler bypass policy, default is not enabled.
Click
Click on a button or link or any other element of a web page.
- Element locator: the XPath of the element in the web page.
Close
Close the current browser or window.
- Current window: The selected window tab in current browser session.
- Current browser: The currently selected browser instance.
Find Single Element
Find the current page according to the specified rules and return the first matching element. Settings are as follows:
-
Find in
- Full page:Find on the whole page.
- Specified area:Find within the specified area on the page.
-
Enter specified locator: If Specified area is selected, you need to enter the Element locator for the specified area.
-
Enter text to search: Enter the text contained in the target element, e.g.
<h1 class="title">Hello, YooginX!</h1>
, if you enter "YooginX", it will match. -
Select element tag:Select the TAG of the target element, the available TAGs are:
- any: Match all TAGs
- link: Same as
<a href="#">Google</a>
in html - p
- span
- div
- expression: Customized TAG
-
Assign target element to a variable:Set the target element to a variable.
Find Multiple Elements
Find the current page according to the specified rules and returns all matched elements. Same as Find Single Element.
Get Columns
Get column elements by the given locators. Configuration steps are as follows:
- Parent element locator: Enter the XPath of the element by which the child elements are wrapped.
- Child element locator: Enter the relative XPath of the child element based on the parent element.
- Select column type: Select the data type of the target element.
- Web element: Instance of the element.
- Link: Value of the attribute
href
(e.g.<a href="https://google.com">Google</a>
). - Text: Text of the element.
- Value: Value of the element (e.g.
<input id="name" value="yooginx">
).
- Assign result columns to a variable: Set the extracted columns to a variable.
Get Table Data
Extract the table data in the web page and convert it to List.
- Element locator: XPath for the table element in web page (e.g.
/html/body/div[3]/div[2]/table
). - Assign target elements to a variable: Set the table data to a variable.
Get Text
Extract the text from the web element.
- Element locator: the XPath of the element in the web page.
- Set text to a variable: Set the text content to a variable.
Input
Enter the given text into the text field.
- Element locator: the XPath of the element in the web page.
- Enter text: Text content.
Maximize
Maximize the current browser.
Navigate Url
Navigate the current browser to the provided url.
- URL: Enter the URL to navigate to.
Press Keys
Simulate the user pressing key(s) to an element.
- Element locator: the XPath of the element in the web page.
- Keystrokes: Key codes, the full key codes can be found here.
Screenshot
Screenshot of the current page. Setting steps are as follows:
- Image file path: Choose the folder path where the screenshot image is to be saved.
- Image file name: Input the image name (e.g. image123.png).
- Captured area: Select the captured area of the page.
- Full page: Capture the whole page.
- Element locator: Input XPath to specify the range of the captured area.
- Overwrite an existing file:Overwrite an existing file when taking screenshot, which is not enabled by default.
- Assign file path to a variable: Set the path of the screenshot image to a variable.
Scroll
Scroll the element into view.
-
Scroll to: Three types of scrolling:
- Top: Scroll to the top of the page.
- Bottom: Scrolll to the bottom of the page.
- Specific element: Scroll the element identified by XPath into view.
-
Element locator:When
Specific element
is selected, you need to enter the XPath of the specified location.
Select Frame
Set the frame identified by locator as the current frame.
-
Locator based on:Choose the type of the element locator:
- XPath expression
- Element id
- Element name
-
Frame locator: Enter XPath / id / name of the specified frame
Unselect Frame
Cancel the previous Select Frame action.
Switch Tab or Window
Switch to the specific browser tab or window.
-
Tab / Window: Select the type of window to switch to:
- Current window
- New window
- Main window
-
Timeout: Specifies the maximum time required to switch to a new window.
Wait Element
Wait until the element is enabled or visible or contains the given text.
- Contains: Wait for the element until it contains the specified text.
- Element locator: the XPath of the element.
- Text:Text content.
- Timeout: Maximum time to wait for the element to fullfill the condition, default 10 seconds.
- Active: Wait for the element until to be enabled.
- Element locator: the XPath of the element.
- Timeout: Maximum time to wait for the element to fullfill the condition, default 10 seconds.
-
Visible: Wait for the element until to be visible.
- Element locator: the XPath of the element.
- Timeout: Maximum time to wait for the element to fullfill the condition, default 10 seconds.
-
Set timeout T/F to a variable: Whether the result times out or not is returned as a system variable
v_b_not_timeout
.
Wait Page Text
Wait until text appears on the current page.
- Text: Text content.
- Timeout: Maximum time to wait, default 10 seconds.
- Set timeout T/F to a variable: Whether the result times out or not is returned as a system variable
v_b_not_timeout
.