Posts

Showing posts from December, 2020

Selenium Interview preparation

Click Element functionality : public void clickElement(WebElement element){ try{ element.click(); }catch(Exception e){ e.printStackTrace(); System.out.println(element +" not clicked"); } Generate random number: public String generateRandomNumber(int length) { char[] chars = "1234567890".toCharArray(); StringBuilder sb = new StringBuilder(); Random random = new Random(); for (int i = 0; i < length; i++) {     char c = chars[random.nextInt(chars.length)];     sb.append(c); } String output = sb.toString(); return (output); } Get first row data : public WebElement getFirstRow() {   return  firstRowData;//xpath for 1st row from UI } Click with Action protected void clickWithAction(WebElement element) { Actions builder = new Actions(driver); builder.click(element).build().perform(); } DoubleClick : public void doubleClick(WebElement element) { Actions builder = new Actions(driver); ...