
These codes parse the XML file and normalize it for test data retrieval.įurther, we use JavaScript methods to get the texts So here is the entire program to read the test data from an XML file.
#Selenium java tutorial by gcreddy code#
These two lines of code create the instance of the DOM architecture of the XML file. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance() ĭocumentBuilder dBuilder = dbf.newDocumentBuilder() Let’s understand the code which is used for parsing the XML file. Test data parsing from XML file in Selenium WebDriver We will further get values of each node written inside the account node. In the above sample XML file, the bank is the head node and account is the child node. Here is the sample XML file whose data we are going to read through Java for our Selenium project. Every element of the node is retrieved by using getElementsByTagName() method. What is Node List?Ī list of nodes which consist of child nodes as well. What is XML Node?Įvery element written inside an XML file is a node. The info from XML DOM is retrieved by using JavaScript methods. The entire DOM looks like the tree structure. What is XML DOM?Īn XML DOM (Document Object Model) is a standard way to access and manipulate the message written inside XML documents.
#Selenium java tutorial by gcreddy driver#
Assume driver is a valid WebDriver instance that My solution differs from others proposed, however, in that you can still use the WebDriver methods for locating the elements. That said, you can use the JavascriptExecutor class to do this. If for example, the code bound to the onclick event of your element invokes window.alert(), you may find your Selenium code hanging, depending on the implementation of the browser driver. Executing a click via JavaScript has some behaviors of which you should be aware.
