11. How do perform drag and drop using WebDriver?
Use Action class
Actions act = new Actions (driver);
WebElement source = driver.findElement (By.xpath (“”)); //source ele which you want to drag
WebElement target = driver.findElement (By.xpath (“”)); //target where you want to drop
12. Give the example for method overload in WebDriver.
Frame (string), frame (int), and frame (WebElement).
13. How do you upload a file?
To upload a file we can use sendKeys() method.
driver.findElement (By.xpath (“input field”)).sendKeys (“path of the file which u want to upload”);
14. How do you click on a menu item in a drop down menu?
If that menu has been created by using select tag then we can use the methods selectByValue () or selectByIndex () or selectByVisibleText (). These are the methods of the Select class.
If the menu has not been created by using the select tag then we can simply find the xpath of that element and click on that to select.
15. Can Captcha be automated?
No, Selenium cannot automate Captcha. Well, the whole concept of Captcha is to ensure that bots and automated programs don’t access sensitive information – which is why, Selenium cannot automate it. The automation test engineer has to manually type the captcha while other fields can be filled automatically.
16. How do you get the current page URL?
17. How does Selenium handle Windows-based pop-ups?
Selenium was designed to handle web applications. Windows-based features are not natively supported by Selenium. However, third-party tools like AutoIT, Robot, etc can be integrated with Selenium to handle pop-ups and other Windows-based features.
18. What is the difference between find Element and find Elements?
Both methods are abstract method of WebDriver interface and used to find the WebElement in a web page. Find Element () – it used to find the one web element. It return only one WebElement type.
FindElements () it used to find more than one web element. It returns List of WebElement.
19. How do you achieve synchronization in WebDriver?
We can use implicit wait.
driver.manage ().timeouts ().implicitly Wait (10, TimeUnit.SECONDS);
Here it will wait for 10sec if while execution driver did not find the element in the page immediately. This code will attach to each and every line of the script automatically. It is not required to write every time. Just write it once after opening the browser.
20. Write the code for Reading and Writing to Excel through Selenium?
FileInputStream fis = new FileInputStream (“path of excel file”);
Workbook wb = WorkbookFactory.create (fis);
Sheet s = wb.getSheet (“sheetName”);
String value = s.getRow (rowNum).getCell (cellNum).getStringCellValue (); // read data
s.getRow (rowNum).getCell (cellNum).setCellValue (“value to be set”); //write data
FileOutputStream FOS = new FileOutputStream (“path of file”);
wb.write (FOS); //save file