For example, need to check if a class of an element contains disabled
before clicking (such as the next and previous icons). Thus, create another function to check if disabled
is not in WebElement, then click the WebElement.
disabled
Or check other attributes of the element that indicate the element's displayed or interactable status.
Get the element first, get the class attribute of the element, and check if it contains the keyword disabled
. Interact with the element if it does not contain disabled
. (or remove the disabled
attribute before interacting with the element)
For example,
An example of what pagination looks like:
https://community.jaspersoft.com/blog/java-selenium-how-navigate-through-web-data-table-using-pagination-buttons-and-verify-displayed
Check the texts of the pagination information elements should display the correct information.
For example, from 101 to 111 in total 2001
If the current page is at the end of the pagination, the next page navigation element should contain disabled
, and should not be clickable.
Wait until the target element with the correct index is displayed or exists.
Wait until the currently selected element (focused page) is different from the previously selected element.
For example, the selected index of the next page is current page +1
(the selected index of the previous page is current page -1
) :
Math.ceil((number of total rows) / (number of rows per page))
Get total count from pagination information element (the information of current display and count of total items might need to be parsed from element text).
Method to get the information string from the information element:
Method to parse numbers in information string:
Get current rows per page from the selected item in the dropdown list, and wait until the element is visible:
Calculate the page index of the last page:
Click the lastPageLink
and verify the currently selected element is the last page:
Common way:
When the previous one does not work, try to use send keyboard key to clear the text in the input fields:
For example:
Loop the current page table rows by using indexes to access data in each row in the table:
When landing on a new page of pagination, get the latest row counts of the current page.
An example of getting all data from the current page, and navigating to the next page:
Methods that are used in the previous block:
It is important to choose the proper data structure/ interface/ class to load data from elements based on CRUD needs.
For example, using 2D lists to store the table elements data.
Need to be aware of the class name of odd and even rows might be different.
Need to understand how tags are designed.
For example, a tag can be a composition of multiple texts or only allow single text. (I think a tag should only have one text, it is a bad design to contain multiple texts in one tag)
One text in one tag
Multiple texts in one tag
Check whether the target element exists or not beforehand.
try catch
Refer to: https://www.softwaretestinghelp.com/exception-handling-framework-selenium-tutorial-19/
To return null
or display error messages, use try catch
to get certain exceptions and deal with them.
Need to use the correct exceptions to catch the correct exception when under certain conditions.
Find element use org.openqa.selenium.By
without org.openqa.selenium.support.ui.WebDriverWait
, and the corresponding Exception:
Find element use org.openqa.selenium.support.ui.WebDriverWait
, and the corresponding Exception:
Add finally after try catch
and call close browser no matter test pass or failed to clean up the tests
When using presence_of_element_located()
to locate and interact with the element, sometimes get this error.
Can use element_to_be_clickable()
before clicking, to make sure the element can be interacted.
selenium
java
test automation
software test