How to use WebDriverException class of org.openqa.selenium package

Best Selenium code snippet using org.openqa.selenium.WebDriverException

WebDriverException org.openqa.selenium.WebDriverException

The WebDriver error - unknown error, happens when the driver tries to process a command and an unspecified error occurs.

The error can generally be isolated to the specific driver. It is a good practice to read the error message for any pointers on why the error occurred.

Example:

The error message shows that Selenium webdriver is not able to focus on element. generally, it happens due to incompatibility between Browser and Driver versions

copy
1Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot focus element 2 (Session info: chrome=61.0.3163.100) 3 (Driver info: chromedriver=2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) 4Command duration or timeout: 0 milliseconds 5Build info: version: 'unknown', revision: 'unknown', time: 'unknown' 6System info: host: 'DWA7DEVOS00170', ip: '10.96.162.167', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_25' 7Driver info: org.openqa.selenium.chrome.ChromeDriver

Solutions:

  • Upgrade browser version
  • Upgrade driver version

Code Snippets

Here are code snippets that can help you understand more how developers are using

Source:SeMethods.java Github

copy

Full Screen

...23 import org.openqa.selenium.NoSuchElementException;24 import org.openqa.selenium.NoSuchFrameException;25 import org.openqa.selenium.NoSuchWindowException;26 import org.openqa.selenium.OutputType;27 import org.openqa.selenium.WebDriverException;28 import org.openqa.selenium.WebElement;29 import org.openqa.selenium.chrome.ChromeDriver;30import org.openqa.selenium.firefox.FirefoxDriver;31import org.openqa.selenium.ie.InternetExplorerDriver;32import org.openqa.selenium.interactions.Actions;33import org.openqa.selenium.remote.RemoteWebDriver;34 import org.openqa.selenium.support.ui.ExpectedConditions;35 import org.openqa.selenium.support.ui.Select;36 import org.openqa.selenium.support.ui.WebDriverWait;3738 import Utilities.Reporter;3940 public class SeMethods extends Reporter implements WdMethods{4142 public RemoteWebDriver driver;43 public String sUrl,primaryWindowHandle,sHubUrl,sHubPort;4445 public SeMethods() {46 Properties prop = new Properties();47 try {48 String path = System.getProperty("user.dir");49 System.out.println(path); 50 prop.load(new FileInputStream(new File(path+"\\data\\config.properties")));51 52 //prop.load(new FileInputStream(new File("C:\\Users\\Omnex\\git\\EwQIMS_POM_Omnex\\EwQIMS_POM\\src\\main\\java\\data\\config.properties")));53 sHubUrl = prop.getProperty("HUB");54 sHubPort = prop.getProperty("PORT");55 sUrl = prop.getProperty("URL");56 57 } catch (FileNotFoundException e) {58 e.printStackTrace();59 } catch (IOException e) {60 e.printStackTrace();61 }62 }636465 public void startApp(String browser) {66 try {67 String path = System.getProperty("user.dir");68 if(browser.equalsIgnoreCase("chrome")) {69 70 System.setProperty("webdriver.chrome.driver",path+"\\drivers\\chromedriver.exe");71 72 //System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");73 driver = new ChromeDriver();74 } else if(browser.equalsIgnoreCase("ie")) {75 System.setProperty("webdriver.ie.driver",path+"\\drivers\\IEDriverServer.exe");76 driver=new InternetExplorerDriver(); }77 else if(browser.equalsIgnoreCase("firefox")) {78 System.setProperty("webdriver.gecko.driver",path+"\\drivers\\geckodriver_32bit.exe");79 driver=new FirefoxDriver(); }80 driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);81 82 driver.get(sUrl);83 84 driver.manage().window().maximize();85 86 87 88 reportStep("The browser:" + browser + " launched successfully", "PASS");89 } catch (WebDriverException e) { 90 reportStep("The browser:" + browser + " could not be launched", "FAIL");91 }92 }9394 public WebElement locateElement(String locator, String locValue) {95 try {96 switch(locator) {97 98 case("id"): return driver.findElementById(locValue);99 case("link"): return driver.findElementByLinkText(locValue);100 case("xpath"):return driver.findElementByXPath(locValue);101 case("name"): return driver.findElementByName(locValue);102 case("class"): return driver.findElementByClassName(locValue);103 case("tag"):return driver.findElementByTagName(locValue);104 }105 } catch (NoSuchElementException e) {106 reportStep("The element with locator "+locator+" and with value "+locValue+" not found.","FAIL");107 throw new RuntimeException();108 } catch (WebDriverException e) {109 reportStep("WebDriverException", "FAIL");110 }111 return null;112 }113 114 public WebElement locateElement(String locValue) {115 return driver.findElementById(locValue);116 }117118119 public void type(WebElement ele, String data) {120 try {121 ele.clear();122 ele.sendKeys(data);123 reportStep("The data: "+data+" entered successfully in field :"+ele, "PASS");124 } catch (InvalidElementStateException e) {125 reportStep("The element: "+ele+" is not interactable","FAIL");126 } catch (WebDriverException e) {127 reportStep("WebDriverException"+e.getMessage(), "FAIL");128 }129 }130131 public void click(WebElement ele) {132 String text = "";133 try {134 WebDriverWait wait = new WebDriverWait(driver,100);135 136 wait.until(ExpectedConditions.elementToBeClickable(ele)); 137 text = ele.getText();138 ele.click();139 reportStep("The element : "+text+" is clicked "+text, "PASS");140 } catch (InvalidElementStateException e) {141 reportStep("The element: "+text+" is not interactable", "FAIL");142 } catch (WebDriverException e) {143 reportStep("WebDriverException"+e.getMessage(), "FAIL");144 } 145146 }147148 149 public void pressEnterKey(WebElement ele) {150 151 try {152 WebDriverWait wait = new WebDriverWait(driver, 10);153 wait.until(ExpectedConditions.elementToBeClickable(ele)); 154 ele.sendKeys(Keys.ENTER);155 reportStep("Enter key is pressed", "PASS");156 } catch (InvalidElementStateException e) {157 reportStep("Enter key is not pressed", "FAIL");158 } catch (WebDriverException e) {159 reportStep("WebDriverException"+e.getMessage(), "FAIL");160 } 161 162 }163 164 public void clickWithNoSnap(WebElement ele) {165 String text = "";166 try {167 WebDriverWait wait = new WebDriverWait(driver, 10);168 wait.until(ExpectedConditions.elementToBeClickable(ele)); 169 text = ele.getText();170 ele.click();171 // switchToWindow(0);172 reportStep("The element :"+text+" is clicked.", "PASS",false);173 } catch (InvalidElementStateException e) {174 reportStep("The element: "+text+" is not interactable", "FAIL",false);175 } catch (WebDriverException e) {176 reportStep("WebDriverException"+e.getMessage(), "FAIL",false);177 } 178 }179180 public String getText(WebElement ele) { 181 String bReturn = "";182 try {183 bReturn = ele.getText();184 } catch (WebDriverException e) {185 reportStep("WebDriverException"+e.getMessage(), "FAIL");186 }187 return bReturn;188 }189190 public String getTitle() { 191 String bReturn = "";192 try {193 bReturn = driver.getTitle();194 } catch (WebDriverException e) {195 reportStep("WebDriverException"+e.getMessage(), "FAIL");196 } 197 return bReturn;198 }199200 public String getAttribute(WebElement ele, String attribute) { 201 String bReturn = "";202 try {203 bReturn= ele.getAttribute(attribute);204 } catch (WebDriverException e) {205 reportStep("WebDriverException"+e.getMessage(), "FAIL");206 } 207 return bReturn;208 }209210 public void selectDropDownUsingText(WebElement ele, String value) {211 try {212 new Select(ele).selectByVisibleText(value);213 reportStep("The dropdown is selected with text "+value,"PASS");214 } catch (WebDriverException e) {215 reportStep("WebDriverException"+e.getMessage(), "FAIL");216 }217218 }219220 public void selectDropDownUsingIndex(WebElement ele, int index) {221 try {222 new Select(ele).selectByIndex(index);223 reportStep("The dropdown is selected with index "+index,"PASS");224 } catch (WebDriverException e) {225 reportStep("WebDriverException"+e.getMessage(), "FAIL");226 } 227228 }229230 public boolean verifyTitle(String expectedTitle) {231 boolean bReturn =false;232 try {233 if(getTitle().equals(expectedTitle)) {234 reportStep("The expected title matches the actual "+expectedTitle,"PASS");235 bReturn= true;236 }else {237 reportStep(getTitle()+" The expected title doesn't matches the actual "+expectedTitle,"FAIL");238 }239 } catch (WebDriverException e) {240 reportStep("WebDriverException : "+e.getMessage(), "FAIL");241 } 242 return bReturn;243244 }245246 public void verifyExactText(WebElement ele, String expectedText) {247 try {248 if(getText(ele).equals(expectedText)) {249 reportStep("The expected text matches the actual "+expectedText,"PASS");250 }else {251 reportStep("The expected text doesn't matches the actual "+expectedText,"FAIL");252 }253 } catch (WebDriverException e) {254 reportStep("WebDriverException : "+e.getMessage(), "FAIL");255 } 256257 }258259 public void verifyPartialText(WebElement ele, String expectedText) {260 try {261 if(getText(ele).contains(expectedText)) {262 reportStep("The expected text contains the actual "+expectedText,"PASS");263 }else {264 reportStep("The expected text doesn't contain the actual "+expectedText,"FAIL");265 }266 } catch (WebDriverException e) {267 reportStep("WebDriverException : "+e.getMessage(), "FAIL");268 } 269 }270271 public void verifyExactAttribute(WebElement ele, String attribute, String value) {272 try {273 if(getAttribute(ele, attribute).equals(value)) {274 reportStep("The expected attribute :"+attribute+" value matches the actual "+value,"PASS");275 }else {276 reportStep("The expected attribute :"+attribute+" value does not matches the actual "+value,"FAIL");277 }278 } catch (WebDriverException e) {279 reportStep("WebDriverException : "+e.getMessage(), "FAIL");280 } 281282 }283284 public void verifyPartialAttribute(WebElement ele, String attribute, String value) {285 try {286 if(getAttribute(ele, attribute).contains(value)) {287 reportStep("The expected attribute :"+attribute+" value contains the actual "+value,"PASS");288 }else {289 reportStep("The expected attribute :"+attribute+" value does not contains the actual "+value,"FAIL");290 }291 } catch (WebDriverException e) {292 reportStep("WebDriverException : "+e.getMessage(), "FAIL");293 }294 }295296 public void verifySelected(WebElement ele) {297 try {298 if(ele.isSelected()) {299 reportStep("The element "+ele+" is selected","PASS");300 } else {301 reportStep("The element "+ele+" is not selected","FAIL");302 }303 } catch (WebDriverException e) {304 reportStep("WebDriverException : "+e.getMessage(), "FAIL");305 }306 }307308 public void verifyDisplayed(WebElement ele) {309 try {310 if(ele.isDisplayed()) {311 reportStep("The element "+ele+" is visible","PASS");312 } else {313 reportStep("The element "+ele+" is not visible","FAIL");314 }315 } catch (WebDriverException e) {316 reportStep("WebDriverException : "+e.getMessage(), "FAIL");317 } 318 }319320 public void switchToWindow(int index) {321 try {322 Set<String> allWindowHandles = driver.getWindowHandles();323 List<String> allHandles = new ArrayList<>();324 allHandles.addAll(allWindowHandles);325 driver.switchTo().window(allHandles.get(index));326 } catch (NoSuchWindowException e) {327 reportStep("The driver could not move to the given window by index "+index,"PASS");328 } catch (WebDriverException e) {329 reportStep("WebDriverException : "+e.getMessage(), "FAIL");330 }331 }332333 public void switchToFrame(WebElement ele) {334 try {335 //driver.switchTo().frame(ele);336 WebDriverWait wait = new WebDriverWait(driver,100);337 wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(ele));338 339 reportStep("switch In to the Frame "+ele,"PASS");340 } catch (NoSuchFrameException e) {341 reportStep("WebDriverException : "+e.getMessage(), "FAIL");342 } catch (WebDriverException e) {343 reportStep("WebDriverException : "+e.getMessage(), "FAIL");344 } 345 }346 347 348 public void switchToMultipleFrames( String frame1, String frame2) {349 try {350 351 352 353 driver.switchTo().frame(frame1).switchTo().frame(frame2);354 355 356 357 reportStep("switch In to the Frame ","PASS");358 } catch (NoSuchFrameException e) {359 reportStep("WebDriverException : "+e.getMessage(), "FAIL");360 } catch (WebDriverException e) {361 reportStep("WebDriverException : "+e.getMessage(), "FAIL");362 } 363 }364 365366 public void acceptAlert() {367 String text = ""; 368 try {369 Alert alert = driver.switchTo().alert();370 text = alert.getText();371 alert.accept();372 reportStep("The alert "+text+" is accepted.","PASS");373 } catch (NoAlertPresentException e) {374 reportStep("There is no alert present.","FAIL");375 } catch (WebDriverException e) {376 reportStep("WebDriverException : "+e.getMessage(), "FAIL");377 } 378 }379380 public void dismissAlert() {381 String text = ""; 382 try {383 Alert alert = driver.switchTo().alert();384 text = alert.getText();385 alert.dismiss();386 reportStep("The alert "+text+" is dismissed.","PASS");387 } catch (NoAlertPresentException e) {388 reportStep("There is no alert present.","FAIL");389 } catch (WebDriverException e) {390 reportStep("WebDriverException : "+e.getMessage(), "FAIL");391 } 392393 }394395 public String getAlertText() {396 String text = ""; 397 try {398 Alert alert = driver.switchTo().alert();399 text = alert.getText();400 } catch (NoAlertPresentException e) {401 reportStep("There is no alert present.","FAIL");402 } catch (WebDriverException e) {403 reportStep("WebDriverException : "+e.getMessage(), "FAIL");404 } 405 return text;406 }407 408 public void rightClickAction(WebElement ele) {409 try {410 Actions action = new Actions(driver);411 action.contextClick(ele).perform();412 reportStep("rightclick action is performed ","PASS");413 }catch (WebDriverException e) {414 reportStep("WebDriverException : "+e.getMessage(), "FAIL");415 }416 }417 418public void doubleClickAction(WebElement ele) {419 try { 420 Actions action = new Actions(driver);421 422 action.doubleClick(ele).perform();423 reportStep("DoubleClick action is performed ","PASS");424 }425 catch (WebDriverException e) {426 reportStep("WebDriverException : "+e.getMessage(), "FAIL");427 }428}429public void explicitWait(WebElement ele) {430 try { 431 WebDriverWait wait=new WebDriverWait(driver, 20);432 wait.until(ExpectedConditions.visibilityOf(ele));433 434 reportStep("The element is waited for 20 secs ","PASS");435 }436 catch (WebDriverException e) {437 reportStep("WebDriverException : "+e.getMessage(), "FAIL");438 }439}440 441 442443public void uploadDocument(String attachment) throws Throwable {444 try {445 String path = System.getProperty("user.dir");446 String filename = path+"\\documentstoupload\\"+attachment;447 // Setting clipboard with file location448 StringSelection stringSelection = new StringSelection(filename);449 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);450 // native key strokes for CTRL, V and ENTER keys451 Robot robot = new Robot();452 robot.keyPress(KeyEvent.VK_CONTROL);453 Thread.sleep(1000);454 robot.keyPress(KeyEvent.VK_V);455 robot.keyRelease(KeyEvent.VK_V);456 Thread.sleep(2000);457 robot.keyRelease(KeyEvent.VK_CONTROL);458 robot.keyPress(KeyEvent.VK_ENTER);459 Thread.sleep(1000);460 robot.keyRelease(KeyEvent.VK_ENTER);461 reportStep("Document from local system has been attached ","PASS");462 }463 catch (WebDriverException e) {464 reportStep("WebDriverException : "+e.getMessage(), "FAIL");465 }466 467 468 469}470 471 472473 public long takeSnap(){474 long number = (long) Math.floor(Math.random() * 900000000L) + 10000000L; 475 try {476 String path = System.getProperty("user.dir");477 FileUtils.copyFile(driver.getScreenshotAs(OutputType.FILE) , new File(path+"//reports//images//"+number+".jpg"));478 } catch (WebDriverException e) {479 System.out.println("The browser has been closed.");480 } catch (IOException e) {481 System.out.println("The snapshot could not be taken");482 }483 return number;484 }485486 public void closeBrowser() {487 try {488 driver.close();489 reportStep("The browser is closed","PASS");490 } catch (Exception e) {491 reportStep("The browser could not be closed","FAIL");492 } ...

Full Screen

Full Screen

Source:BrowserActions.java Github

copy

Full Screen

...13import org.openqa.selenium.NoAlertPresentException;14import org.openqa.selenium.NoSuchElementException;15import org.openqa.selenium.NoSuchFrameException;16import org.openqa.selenium.NoSuchWindowException;17import org.openqa.selenium.WebDriverException;18import org.openqa.selenium.WebElement;19import org.openqa.selenium.interactions.Actions;20import org.openqa.selenium.support.ui.Select;21import salesforce.base.SalesforceBase;22public class BrowserActions extends SalesforceBase implements IBrowserActions{23 public BrowserActions() {24 this.driver = getDriver();25 }26 public WebElement locateElement(String locator, String locValue) {27 try {28 29 switch (locator.toLowerCase()) {30 case "id": return driver.findElement(By.id(locValue));31 case "name": return driver.findElement(By.name(locValue));32 case "class": return driver.findElement(By.className(locValue));33 case "link" : return driver.findElement(By.linkText(locValue));34 case "xpath": return webDriverWait4VisibilityOfEle(driver.findElement(By.xpath(locValue))); 35 default:36 break;37 }38 } catch (NoSuchElementException e) {39 reportStep("The element with locator "+locator+" not found.","FAIL");40 } catch (WebDriverException e) {41 reportStep("Unknown exception occured while finding "+locator+" with the value "+locValue, "FAIL");42 }43 return null;44 }45 46 public List<WebElement> locateElements(String type, String value) {47 try {48 switch(type.toLowerCase()) {49 case "id": return driver.findElementsById(value);50 case "name": return driver.findElementsByName(value);51 case "class": return driver.findElementsByClassName(value);52 case "link": return driver.findElementsByLinkText(value);53 case "xpath": return driver.findElementsByXPath(value);54 }55 } catch (WebDriverException e) {56 reportStep("Unknown exception occured while finding "+type+" with the value "+value, "FAIL");57 }58 return null;59 }60 61 public WebElement locateElement(String locValue) {62 return driver.findElement(By.id(locValue));63 }64 65 public void type(WebElement ele, String data) {66 try {67 webDriverWait4VisibilityOfEle(ele);68 ele.clear();69 ele.sendKeys(data);70// reportStep("The data: "+data+" entered successfully in the field :"+ele, "PASS");71 } catch (InvalidElementStateException e) {72 reportStep("The data: "+data+" could not be entered in the field :"+ele,"FAIL");73 } catch (WebDriverException e) {74 reportStep("Unknown exception occured while entering "+data+" in the field :"+ele, "FAIL");75 }76 }77 78 public void typeAndEnter(WebElement ele, String data) {79 try {80 webDriverWait4VisibilityOfEle(ele);81 ele.clear();82 ele.sendKeys(data);83 ele.sendKeys(Keys.ENTER);84 reportStep("The data: "+data+" entered successfully in the field :"+ele, "PASS");85 } catch (InvalidElementStateException e) {86 reportStep("The data: "+data+" could not be entered in the field :"+ele,"FAIL");87 } catch (WebDriverException e) {88 reportStep("Unknown exception occured while entering "+data+" in the field :"+ele, "FAIL");89 }90 }91 92 public void sendkeysUsingActions(WebElement ele, Keys arrowDown) {93 try {94 Actions actions = new Actions(driver);95 actions.sendKeys(arrowDown).perform();96 reportStep("The data: "+arrowDown+" entered successfully in the field :"+ele, "PASS");97 } catch (InvalidElementStateException e) {98 reportStep("The data: "+arrowDown+" could not be entered in the field :"+ele,"FAIL");99 } catch (WebDriverException e) {100 reportStep("Unknown exception occured while entering "+arrowDown+" in the field :"+ele, "FAIL");101 }102 }103 104 public void typeUsingActions(WebElement ele, String data) {105 try {106 Actions actions = new Actions(driver);107 ele.clear();108 actions.sendKeys(data).perform();109 reportStep("The data: "+data+" entered successfully in the field :"+ele, "PASS");110 } catch (InvalidElementStateException e) {111 reportStep("The data: "+data+" could not be entered in the field :"+ele,"FAIL");112 } catch (WebDriverException e) {113 reportStep("Unknown exception occured while entering "+data+" in the field :"+ele, "FAIL");114 }115 }116 public void click(WebElement ele) {117 String text = "";118 try {119 webDriverWait4ElementToBeClickable(ele);120 text = ele.getText();121 ele.click();122 reportStep("The element "+text+" is clicked", "PASS");123 } catch (InvalidElementStateException e) {124 reportStep("The element: "+text+" could not be clicked", "FAIL");125 } catch (WebDriverException e) {126 reportStep("Unknown exception occured while clicking in the field :", "FAIL");127 } 128 }129 130 public void clickByJS(WebElement ele) {131 JavascriptExecutor js = (JavascriptExecutor)driver;132 try {133 js.executeScript("arguments[0].click();", ele);134 reportStep("The element is clicked by javascript click event", "PASS");135 } catch (JavascriptException e) {136 reportStep("The element could not be clicked", "FAIL");137 } catch (WebDriverException e) {138 reportStep("Unknown exception occured while clicking in the field :", "FAIL");139 } 140 }141 142 public void clickByActions(WebElement ele) {143 Actions actions = new Actions(driver);144 try {145 actions.moveToElement(ele).click().perform();146 reportStep("The element is clicked by actions", "PASS");147 } catch (ElementClickInterceptedException e) {148 reportStep("The element could not be clicked", "FAIL");149 } catch (ElementNotInteractableException e) {150 reportStep("The element could not be clicked", "FAIL");151 } catch (WebDriverException e) {152 reportStep("Unknown exception occured while clicking in the field :", "FAIL");153 } 154 }155 156 public void scrollToVisibleElement(WebElement ele)157 {158 JavascriptExecutor js = (JavascriptExecutor)driver;159 webDriverWait4VisibilityOfEle(ele);160 try {161 js.executeScript("arguments[0].scrollIntoView();", ele);162 } catch (JavascriptException e) {163 e.printStackTrace();164 } catch (Exception e) {165 e.printStackTrace();166 }167 }168 169 public void scrollToPageEnd()170 {171 JavascriptExecutor js = (JavascriptExecutor)driver;172 try {173 js.executeScript("window.scrollTo(0, document.body.scrollHeight)");174 } catch (JavascriptException e) {175 e.printStackTrace();176 } catch (Exception e) {177 e.printStackTrace();178 }179 }180 181 public void highlightElement(WebElement ele)182 {183 JavascriptExecutor js = (JavascriptExecutor)driver;184 try {185 js.executeScript("arguments[0].style.border='3px solid red'",ele);186 } catch (JavascriptException e) {187 e.printStackTrace();188 } catch (Exception e) {189 e.printStackTrace();190 }191 }192 193 public void clickWithNoSnap(WebElement ele) {194 String text = "";195 try {196 webDriverWait4ElementToBeClickable(ele); 197 text = ele.getText();198 ele.click(); 199 reportStep("The element :"+text+" is clicked.", "PASS",false);200 } catch (InvalidElementStateException e) {201 reportStep("The element: "+text+" could not be clicked", "FAIL",false);202 } catch (WebDriverException e) {203 reportStep("Unknown exception occured while clicking in the field :","FAIL",false);204 } 205 }206 public String getText(WebElement ele) { 207 String bReturn = "";208 try {209 webDriverWait4VisibilityOfEle(ele);210 bReturn = ele.getText();211 } catch (WebDriverException e) {212 reportStep("The element: "+ele+" could not be found.", "FAIL");213 }214 return bReturn;215 }216 public String getTitle() { 217 String bReturn = "";218 try {219 bReturn = driver.getTitle();220 } catch (WebDriverException e) {221 reportStep("Unknown Exception Occured While fetching Title", "FAIL");222 } 223 return bReturn;224 }225 public String getAttribute(WebElement ele, String attribute) { 226 String bReturn = "";227 try {228 webDriverWait4VisibilityOfEle(ele);229 bReturn= ele.getAttribute(attribute);230 } catch (WebDriverException e) {231 reportStep("The element: "+ele+" could not be found.", "FAIL");232 } 233 return bReturn;234 }235 public void selectDropDownUsingVisibleText(WebElement ele, String value) {236 try {237 new Select(ele).selectByVisibleText(value);238 reportStep("The dropdown is selected with text "+value,"PASS");239 } catch (WebDriverException e) {240 reportStep("The element: "+ele+" could not be found.", "FAIL");241 }242 }243 public void selectDropDownUsingIndex(WebElement ele, int index) {244 try {245 new Select(ele).selectByIndex(index);246 reportStep("The dropdown is selected with index "+index,"PASS");247 } catch (WebDriverException e) {248 reportStep("The element: "+ele+" could not be found.", "FAIL");249 } 250 }251 public boolean verifyExactTitle(String title) {252 boolean bReturn =false;253 try {254 if(getTitle().equals(title)) {255 reportStep("The title of the page matches with the value :"+title,"PASS");256 bReturn= true;257 }else {258 reportStep("The title of the page:"+driver.getTitle()+" did not match with the value :"+title, "FAIL");259 }260 } catch (WebDriverException e) {261 reportStep("Unknown exception occured while verifying the title", "FAIL");262 } 263 return bReturn;264 }265 public void verifyExactText(WebElement ele, String expectedText) {266 try {267 if(getText(ele).equals(expectedText)) {268 reportStep("The text: "+getText(ele)+" matches with the value :"+expectedText,"PASS");269 }else {270 reportStep("The text "+getText(ele)+" doesn't matches the actual "+expectedText,"FAIL");271 }272 } catch (WebDriverException e) {273 reportStep("Unknown exception occured while verifying the Text", "FAIL");274 } 275 }276 public void verifyPartialText(WebElement ele, String expectedText) {277 try {278 if(getText(ele).contains(expectedText)) {279 reportStep("The expected text contains the actual "+expectedText,"PASS");280 }else {281 reportStep("The expected text doesn't contain the actual "+expectedText,"FAIL");282 }283 } catch (WebDriverException e) {284 reportStep("Unknown exception occured while verifying the Text", "FAIL");285 } 286 }287 public void verifyExactAttribute(WebElement ele, String attribute, String value) {288 try {289 if(getAttribute(ele, attribute).equals(value)) {290 reportStep("The expected attribute :"+attribute+" value matches the actual "+value,"PASS");291 }else {292 reportStep("The expected attribute :"+attribute+" value does not matches the actual "+value,"FAIL");293 }294 } catch (WebDriverException e) {295 reportStep("Unknown exception occured while verifying the Attribute Text", "FAIL");296 } 297 }298 public void verifyPartialAttribute(WebElement ele, String attribute, String value) {299 try {300 if(getAttribute(ele, attribute).contains(value)) {301 reportStep("The expected attribute :"+attribute+" value contains the actual "+value,"PASS");302 }else {303 reportStep("The expected attribute :"+attribute+" value does not contains the actual "+value,"FAIL");304 }305 } catch (WebDriverException e) {306 reportStep("Unknown exception occured while verifying the Attribute Text", "FAIL");307 }308 }309 public void verifySelected(WebElement ele) {310 try {311 if(ele.isSelected()) {312 reportStep("The element "+ele+" is selected","PASS");313 } else {314 reportStep("The element "+ele+" is not selected","FAIL");315 }316 } catch (WebDriverException e) {317 reportStep("WebDriverException : "+e.getMessage(), "FAIL");318 }319 }320 public void verifyDisplayed(WebElement ele) {321 try {322 if(ele.isDisplayed()) {323 reportStep("The element "+ele+" is visible","PASS");324 } else {325 reportStep("The element "+ele+" is not visible","FAIL");326 }327 } catch (WebDriverException e) {328 reportStep("WebDriverException : "+e.getMessage(), "FAIL");329 } 330 }331 public void switchToWindow(int index) {332 try {333 Set<String> allWindowHandles = driver.getWindowHandles();334 List<String> allHandles = new ArrayList<>();335 allHandles.addAll(allWindowHandles);336 driver.switchTo().window(allHandles.get(index));337 } catch (NoSuchWindowException e) {338 reportStep("The driver could not move to the given window by index "+index,"PASS");339 } catch (WebDriverException e) {340 reportStep("WebDriverException : "+e.getMessage(), "FAIL");341 }342 }343 public void switchToFrame(WebElement ele) {344 try {345 webDriverWait4FrameToBeAvailableAndSwitchTo(ele);346 reportStep("switch In to the Frame "+ele,"PASS");347 } catch (NoSuchFrameException e) {348 reportStep("WebDriverException : "+e.getMessage(), "FAIL");349 } catch (WebDriverException e) {350 reportStep("WebDriverException : "+e.getMessage(), "FAIL");351 } 352 }353 354 public void switchToFrame(int index) {355 try {356 webDriverWait4FrameToBeAvailableAndSwitchTo(index);357 reportStep("switch In to the Frame "+index,"PASS");358 } catch (NoSuchFrameException e) {359 reportStep("WebDriverException : "+e.getMessage(), "FAIL");360 } catch (WebDriverException e) {361 reportStep("WebDriverException : "+e.getMessage(), "FAIL");362 } 363 }364 365 public void switchToDefaultContent() {366 try {367 driver.switchTo().defaultContent();}368 catch (WebDriverException e) {369 reportStep("WebDriverException : "+e.getMessage(), "FAIL");370 } 371 }372 373 public void acceptAlert() {374 String text = ""; 375 try {376 Alert alert = driver.switchTo().alert();377 text = alert.getText();378 alert.accept();379 reportStep("The alert "+text+" is accepted.","PASS");380 } catch (NoAlertPresentException e) {381 reportStep("There is no alert present.","FAIL");382 } catch (WebDriverException e) {383 reportStep("WebDriverException : "+e.getMessage(), "FAIL");384 } 385 }386 public void dismissAlert() {387 String text = ""; 388 try {389 Alert alert = driver.switchTo().alert();390 text = alert.getText();391 alert.dismiss();392 reportStep("The alert "+text+" is dismissed.","PASS");393 } catch (NoAlertPresentException e) {394 reportStep("There is no alert present.","FAIL");395 } catch (WebDriverException e) {396 reportStep("WebDriverException : "+e.getMessage(), "FAIL");397 } 398 }399 public String getAlertText() {400 String text = ""; 401 try {402 Alert alert = driver.switchTo().alert();403 text = alert.getText();404 } catch (NoAlertPresentException e) {405 reportStep("There is no alert present.","FAIL");406 } catch (WebDriverException e) {407 reportStep("WebDriverException : "+e.getMessage(), "FAIL");408 } 409 return text;410 }411 public void closeActiveBrowser() {412 try {413 driver.close();414 reportStep("The browser is closed","PASS", false);415 } catch (Exception e) {416 reportStep("The browser could not be closed","FAIL", false);417 }418 }419 public void closeAllBrowsers() {420 try {421 driver.quit();422 reportStep("The opened browsers are closed","PASS", false);423 } catch (Exception e) {424 reportStep("Unexpected error occured in Browser","FAIL", false);425 }426 }427 public void selectDropDownUsingValue(WebElement ele, String value) {428 try {429 new Select(ele).selectByValue(value);430 reportStep("The dropdown is selected with text "+value,"PASS");431 } catch (WebDriverException e) {432 reportStep("The element: "+ele+" could not be found.", "FAIL");433 }434 }435 @Override436 public boolean verifyPartialTitle(String title) {437 boolean bReturn =false;438 try {439 if(getTitle().contains(title)) {440 reportStep("The title of the page matches with the value :"+title,"PASS");441 bReturn= true;442 }else {443 reportStep("The title of the page:"+driver.getTitle()+" did not match with the value :"+title, "FAIL");444 }445 } catch (WebDriverException e) {446 reportStep("Unknown exception occured while verifying the title", "FAIL");447 } 448 return bReturn; 449 }450}...

Full Screen

Full Screen

Source:ImplementationClass.java Github

copy

Full Screen

...7import org.openqa.selenium.ElementNotInteractableException;8import org.openqa.selenium.NoSuchFrameException;9import org.openqa.selenium.StaleElementReferenceException;10import org.openqa.selenium.WebDriver;11import org.openqa.selenium.WebDriverException;12import org.openqa.selenium.WebElement;13import org.openqa.selenium.chrome.ChromeDriver;14import org.openqa.selenium.chrome.ChromeDriverService;15import org.openqa.selenium.chrome.ChromeOptions;16import org.openqa.selenium.firefox.FirefoxDriver;17import org.openqa.selenium.firefox.FirefoxOptions;18import org.openqa.selenium.remote.RemoteWebDriver;19import org.openqa.selenium.support.ui.ExpectedConditions;20import org.openqa.selenium.support.ui.WebDriverWait;2122public class ImplementationClass implements ProjectInterfaceDesign {2324 public static RemoteWebDriver driver;2526 public void launchApplication(String browserName, String Url) {27 try {28 if (browserName.equalsIgnoreCase("chrome")) {29 System.setProperty("webdriver.chrome.driver", "./chromedriver.exe");30 System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true");31 // to handle browser notifications32 ChromeOptions options = new ChromeOptions();33 ChromeOptions browserArguments = options.addArguments("--disable-notificatins", "--start-maximized");34 // Initiallizing chromeDriver35 ChromeDriver driver = new ChromeDriver(browserArguments);36 // implicitly wait for 30 sec37 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);38 // maximze the window39 driver.manage().window().maximize();40 // url41 driver.get(Url);42 } else if (browserName.equalsIgnoreCase("firefox")) {43 System.setProperty("webdriver.gecko.driver", ".Drivers/geckodriver.exe");44 // to handle browser notifications45 FirefoxOptions options = new FirefoxOptions();46 FirefoxOptions browserArguments = options.addArguments("--disable-notificatins", "--start-maximized");47 // Initiallizing chromeDriver48 FirefoxDriver driver = new FirefoxDriver(browserArguments);49 // implicitly wait for 30 sec50 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);51 // maximze the window52 driver.manage().window().maximize();53 // url54 driver.get(Url);55 }56 } catch (WebDriverException e) {57 System.out.println("WebDriverException" + e + "occures please check the launchApplication method");58 }5960 }6162 public WebElement locateElementBy(String locator, String LocatorValue) {63 try {64 switch (locator) {65 case "id":66 return driver.findElementById(LocatorValue);67 case "tagname":68 return driver.findElementByTagName(LocatorValue);69 case "name":70 return driver.findElementByName(LocatorValue);71 case "class":72 return driver.findElementByClassName(LocatorValue);73 case "xpath":74 return driver.findElementByXPath(LocatorValue);75 }76 } catch (NoSuchElementException e) {77 System.out.println("The element " + LocatorValue + "could not find using locator" + locator);78 } catch (WebDriverException e) {79 System.out.println("WebDriverException" + e + "occures please check the launchApplication method");80 }81 return null;82 }8384 public WebElement locateElementID(String ID) {85 try {86 return driver.findElementById(ID);87 } catch (NoSuchElementException e) {88 System.out.println("The element " + ID + "could not find using ID locator");89 } catch (WebDriverException e) {90 System.out.println("WebDriverException" + e + "occures please check the launchApplication method");91 }92 return null;93 }9495 public WebElement locateElementXPath(String XPath) {96 try {97 return driver.findElementById(XPath);98 } catch (NoSuchElementException e) {99 System.out.println("The element " + XPath + "could not find using XPath");100 } catch (WebDriverException e) {101 System.out.println("WebDriverException" + e + "occures please check the launchApplication method");102 }103 return null;104 }105106 public void enterData(WebElement inputElement, String sendkeysData) {107 try {108 inputElement.sendKeys(sendkeysData);109 } catch (IllegalArgumentException e) {110 System.out111 .println("the data" + sendkeysData + "could not enter into the webelement due to illegalAgrument");112 } catch (ElementNotInteractableException e) {113 System.out.println("the data" + sendkeysData114 + "could not enter into the webelement due to not interactable due to element is not pointer or keyboad interactable");115 } catch (WebDriverException e) {116 System.out.println("WebDriverException" + e + "occures please check the launchApplication method");117 }118 }119120 public void click(WebElement clickElement) {121 try {122 WebDriverWait wait = new WebDriverWait(driver, 10);123 wait.until(ExpectedConditions.elementToBeClickable(clickElement));124 String text = clickElement.getText();125 clickElement.click();126 System.out.println("The Button " + text + "clicked sucessfully");127 } catch (StaleElementReferenceException e) {128 System.out.println("the element no longer appears on the DOM of the page.");129 } catch (ElementClickInterceptedException e) {130 System.out.println("the button was unable to click due to intersception");131 } catch (WebDriverException e) {132 System.out.println("WebDriverException" + e + "occures please check the launchApplication method");133 }134135 }136137 138 public void frameByWebElement(WebElement frameElement) {139 try {140 driver.switchTo().frame(frameElement);141 System.out.println("currently switched to frame");142 } catch (NoSuchFrameException e) {143 System.out.println("No such frame found ");144 }catch (WebDriverException e) {145 System.out.println("WebDriverException" + e + "occures please check the launchApplication method");146 }147 }148149150 public void frameByName(String Name) {151 try {152 driver.switchTo().frame(Name);153 System.out.println("currently switched to frame");154 } catch (NoSuchFrameException e) {155 System.out.println("No such frame found ");156 }catch (WebDriverException e) {157 System.out.println("WebDriverException" + e + "occures please check the launchApplication method");158 }159 160 }161162 @Override163 public void parentFrame() {164 // TODO Auto-generated method stub165166 }167168 @Override169 public void defaultFrame() {170 // TODO Auto-generated method stub171172 }173174 @Override175 public void alert() {176 // TODO Auto-generated method stub177178 }179180 @Override181 public void acceptAlert() {182 // TODO Auto-generated method stub183184 }185186 @Override187 public void dismissAlert() {188 // TODO Auto-generated method stub189190 }191192 @Override193 public String AlertText() {194 // TODO Auto-generated method stub195 return null;196 }197198 @Override199 public String getText(WebElement ele) {200 // TODO Auto-generated method stub201 return null;202 }203204 205 public void getTitle() {206 String title="";207 try {208 title = driver.getTitle();209 System.out.println("Login to the page"+title+"successfully");210 } catch (java.lang.NullPointerException e) {211 System.out.println("WebDriverException" + e + "occures "); }212 213 }214215} ...

Full Screen

Full Screen

Source:DefaultGenericMobileElement.java Github

copy

Full Screen

...15 */16package io.appium.java_client;17import com.google.common.collect.ImmutableMap;18import org.openqa.selenium.By;19import org.openqa.selenium.WebDriverException;20import org.openqa.selenium.WebElement;21import org.openqa.selenium.internal.FindsByClassName;22import org.openqa.selenium.internal.FindsByCssSelector;23import org.openqa.selenium.internal.FindsById;24import org.openqa.selenium.internal.FindsByLinkText;25import org.openqa.selenium.internal.FindsByName;26import org.openqa.selenium.internal.FindsByTagName;27import org.openqa.selenium.internal.FindsByXPath;28import org.openqa.selenium.remote.RemoteWebElement;29import org.openqa.selenium.remote.Response;30import java.util.List;31import java.util.Map;32@SuppressWarnings({"unchecked", "rawtypes"})33abstract class DefaultGenericMobileElement<T extends WebElement> extends RemoteWebElement34 implements FindsByClassName,35 FindsByCssSelector, FindsById,36 FindsByLinkText, FindsByName, FindsByTagName, FindsByXPath, FindsByFluentSelector<T>, FindsByAccessibilityId<T>,37 ExecutesMethod, TouchableElement<T> {38 @Override public Response execute(String driverCommand, Map<String, ?> parameters) {39 return super.execute(driverCommand, parameters);40 }41 @Override public Response execute(String command) {42 return super.execute(command, ImmutableMap.<String, Object>of());43 }44 @Override public List findElements(By by) {45 return super.findElements(by);46 }47 @Override public List findElements(String by, String using) {48 return super.findElements(by, using);49 }50 @Override public T findElement(By by) {51 return (T) super.findElement(by);52 }53 @Override public T findElement(String by, String using) {54 return (T) super.findElement(by, using);55 }56 @Override public List findElementsById(String id) {57 return super.findElementsById(id);58 }59 @Override public T findElementById(String id) {60 return (T) super.findElementById(id);61 }62 /**63 * @throws WebDriverException his method doesn't work against native app UI.64 */65 public T findElementByLinkText(String using) throws WebDriverException {66 return (T) super.findElementByLinkText(using);67 }68 /**69 * @throws WebDriverException This method doesn't work against native app UI.70 */71 public List findElementsByLinkText(String using) throws WebDriverException {72 return super.findElementsByLinkText(using);73 }74 /**75 * @throws WebDriverException his method doesn't work against native app UI.76 */77 public T findElementByPartialLinkText(String using) throws WebDriverException {78 return (T) super.findElementByPartialLinkText(using);79 }80 /**81 * @throws WebDriverException This method doesn't work against native app UI.82 */83 public List findElementsByPartialLinkText(String using) throws WebDriverException {84 return super.findElementsByPartialLinkText(using);85 }86 public T findElementByTagName(String using) {87 return (T) super.findElementByTagName(using);88 }89 public List findElementsByTagName(String using) {90 return super.findElementsByTagName(using);91 }92 public T findElementByName(String using) {93 return (T) super.findElementByName(using);94 }95 public List findElementsByName(String using) {96 return super.findElementsByName(using);97 }98 public T findElementByClassName(String using) {99 return (T) super.findElementByClassName(using);100 }101 public List findElementsByClassName(String using) {102 return super.findElementsByClassName(using);103 }104 /**105 * @throws WebDriverException his method doesn't work against native app UI.106 */107 public T findElementByCssSelector(String using) throws WebDriverException {108 return (T) super.findElementByCssSelector(using);109 }110 /**111 * @throws WebDriverException This method doesn't work against native app UI.112 */113 public List findElementsByCssSelector(String using) throws WebDriverException {114 return super.findElementsByCssSelector(using);115 }116 public T findElementByXPath(String using) {117 return (T) super.findElementByXPath(using);118 }119 public List findElementsByXPath(String using) {120 return super.findElementsByXPath(using);121 }122 /**123 * @throws WebDriverException because it may not work against native app UI.124 */125 public void submit() throws WebDriverException {126 super.submit();127 }128 /**129 * @throws WebDriverException because it may not work against native app UI.130 */131 public String getCssValue(String propertyName) throws WebDriverException {132 return super.getCssValue(propertyName);133 }134}...

Full Screen

Full Screen

Source:Reusables.java Github

copy

Full Screen

1package com.reusables;2import java.util.concurrent.TimeUnit;3import org.openqa.selenium.JavascriptExecutor;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebDriverException;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.chrome.ChromeDriver;8import org.openqa.selenium.chrome.ChromeOptions;9import org.openqa.selenium.firefox.FirefoxDriver;10import org.openqa.selenium.firefox.FirefoxDriverLogLevel;11import org.openqa.selenium.firefox.FirefoxOptions;12import org.openqa.selenium.remote.RemoteWebDriver;13import org.openqa.selenium.support.ui.ExpectedConditions;14import org.openqa.selenium.support.ui.Select;15import org.openqa.selenium.support.ui.WebDriverWait;16import io.github.bonigarcia.wdm.WebDriverManager;17public class Reusables {18 public static RemoteWebDriver driver;19 // WebDriver driver;20 private static JavascriptExecutor jse = null;21 public void EnterURL(String applicationUrl) {22 try {23 driver.get(applicationUrl);24 } catch (Exception e) {25 System.out.println(e.getStackTrace());26 }27 }28 public void StartApplication(String browser) {29 try {30 if (browser.equalsIgnoreCase("chrome")) {31 ChromeOptions options = new ChromeOptions();32 options.addArguments("test-type");33 options.addArguments("ignore-certificate-errors");34 options.setAcceptInsecureCerts(true);35 WebDriverManager.chromedriver().setup();36 driver = new ChromeDriver(options);37 } else if (browser.equalsIgnoreCase("firefox")) {38 WebDriverManager.firefoxdriver().setup();39 System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");40 FirefoxOptions options = new FirefoxOptions();41 options.setLogLevel(FirefoxDriverLogLevel.ERROR);42 driver = new FirefoxDriver(options);43 } else {44 System.out.println("Unknown Browser");45 }46 driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);47 driver.manage().window().maximize();48 jse = (JavascriptExecutor) driver;49 } catch (Exception e) {50 System.out.println(e.getStackTrace());51 }52 }53 public void iType(WebElement ele, String data) {54 try {55 ele.clear();56 ele.sendKeys(data);57 } catch (WebDriverException e) {58 System.out.println(e.getStackTrace());59 }60 }61 public String igetTitle() {62 String bReturn = "";63 try {64 bReturn = driver.getTitle();65 } catch (WebDriverException e) {66 System.out.println(e.getStackTrace());67 }68 return bReturn;69 }70 public void SelectDropDownUsingText(WebElement ele, String value) {71 try {72 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);73 System.out.println("enter blocl value" + value);74 System.out.println("ele value" + ele);75 new Select(ele).selectByVisibleText(value);76 System.out.println("selected value");77 } catch (WebDriverException e) {78 System.out.println(e.getStackTrace());79 }80 }81 public void Click(WebElement ele) {82 try {83 ele.click();84 } catch (WebDriverException e) {85 System.out.println(e.getStackTrace());86 }87 }88 public void SelectDropDownUsingIndex(WebElement ele, int index) {89 try {90 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);91 new Select(ele).selectByIndex(index);92 } catch (WebDriverException e) {93 System.out.println(e.getStackTrace());94 }95 }96 public void ImplicitlyWait(int seconds) {97 driver.manage().timeouts().implicitlyWait(seconds, TimeUnit.SECONDS);98 }99 public void iExplicitWaitForElementToBeClicable(WebElement ele, long sec) {100 try {101 WebDriverWait wait = new WebDriverWait(driver, sec);102 wait.until(ExpectedConditions.elementToBeClickable(ele));103 } catch (WebDriverException e) {104 System.out.println(e.getStackTrace());105 }106 }107 public String iGetCurrentURL() {108 String currentURL = "";109 try {110 currentURL = driver.getCurrentUrl();111 } catch (WebDriverException e) {112 System.out.println(e.getStackTrace());113 }114 return currentURL;115 }116 117 public boolean iVerifyCurrentURL(String expectedTitle) {118 boolean bReturn = false;119 try {120 if (iGetCurrentURL().contains(expectedTitle)) {121 bReturn = true;122 } else {123 System.out.println("i failed to verify current url of the element: " + expectedTitle);124 }125 } catch (WebDriverException e) {126 System.out.println(e.getStackTrace());127 }128 return bReturn;129 }130}...

Full Screen

Full Screen

Source:Driver.java Github

copy

Full Screen

1package com.cybertek.utilities;2import io.github.bonigarcia.wdm.WebDriverManager;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebDriverException;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.chrome.ChromeOptions;7import org.openqa.selenium.edge.EdgeDriver;8import org.openqa.selenium.firefox.FirefoxDriver;9import org.openqa.selenium.firefox.FirefoxOptions;10import org.openqa.selenium.ie.InternetExplorerDriver;11import org.openqa.selenium.safari.SafariDriver;12public class Driver {13 private Driver() {}14 private static WebDriver driver;15 public static WebDriver getDriver() {16 if (driver == null) {17 String browser = ConfigurationReader.getKey("browser");18 switch (browser) {19 case "chrome":20 WebDriverManager.chromedriver().setup();21 driver = new ChromeDriver();22 break;23 case "chrome-headless":24 WebDriverManager.chromedriver().setup();25 driver = new ChromeDriver(new ChromeOptions().setHeadless(true));26 break;27 case "firefox":28 WebDriverManager.firefoxdriver().setup();29 driver = new FirefoxDriver();30 break;31 case "firefox-headless":32 WebDriverManager.firefoxdriver().setup();33 driver = new FirefoxDriver(new FirefoxOptions().setHeadless(true));34 break;35 case "ie":36 if (!System.getProperty("os.name").toLowerCase().contains("windows"))37 throw new WebDriverException("Your OS doesn't support Internet Explorer");38 WebDriverManager.iedriver().setup();39 driver = new InternetExplorerDriver();40 break;41 case "edge":42 if (!System.getProperty("os.name").toLowerCase().contains("windows"))43 throw new WebDriverException("Your OS doesn't support Edge");44 WebDriverManager.edgedriver().setup();45 driver = new EdgeDriver();46 break;47 case "safari":48 if (!System.getProperty("os.name").toLowerCase().contains("mac"))49 throw new WebDriverException("Your OS doesn't support Safari");50 WebDriverManager.getInstance(SafariDriver.class).setup();51 driver = new SafariDriver();52 break;53 }54 }55 return driver;56 }57 public static void closeDriver() {58 if (driver != null) {59 driver.quit();60 driver = null;61 }62 }63}...

Full Screen

Full Screen

WebDriverException

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriverException;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.openqa.selenium.remote.RemoteWebDriver;4import java.net.URL;5import java.net.MalformedURLException;6import java.io.File;7import java.io.FileInputStream;8import java.io.IOException;9import java.util.Properties;10import org.openqa.selenium.By;11import org.openqa.selenium.WebElement;12import org.openqa.selenium.WebDriver;13import org.openqa.selenium.firefox.FirefoxDriver;14import org.openqa.selenium.chrome.ChromeDriver;15import org.openqa.selenium.ie.InternetExplorerDriver;16import org.openqa.selenium.edge.EdgeDriver;17import org.openqa.selenium.support.ui.WebDriverWait;18import org.openqa.selenium.support.ui.ExpectedConditions;19import java.util.concurrent.TimeUnit;20import org.openqa.selenium.interactions.Actions;21import org.openqa.selenium.JavascriptExecutor;22import org.openqa.selenium.Dimension;23import org.openqa.selenium.Point;24import org.openqa.selenium.Alert;25import org.openqa.selenium.Keys;26import org.openqa.selenium

Full Screen

Full Screen

WebDriverException

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriverException;2import org.openqa.selenium.By;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.remote.DesiredCapabilities;5import org.openqa.selenium.remote.RemoteWebDriver;6import org.openqa.selenium.remote.DesiredCapabilities;7import java.net.URL;8import java.io.IOException;9import java.io.FileInputStream;10import java.util.Properties;11import java.lang.InterruptedException;12import io.appium.java_client.MobileElement;13import io.appium.java_client.android.AndroidDriver;14import io.appium.java_client.android.AndroidElement;15import io.appium.java_client.AppiumDriver;16import io.appium.java_client.MobileBy;17import org.openqa.selenium.support.ui.WebDriverWait;18import org.openqa.selenium.support.ui.ExpectedConditions;19import java.util.concurrent.TimeUnit;20import java.util.concurrent.TimeUnit;21import io.appium.java_client.MobileDriver;22import io.appium.java_client.MobileElement;23import org.openqa.selenium.support.ui.ExpectedConditions;24import java.util.concurrent.TimeUnit;

Full Screen

Full Screen

WebDriverException

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriverException;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.By;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.support.ui.WebDriverWait;7import org.openqa.selenium.support.ui.ExpectedConditions;8import java.util.concurrent.TimeUnit;9import org.openqa.selenium.interactions.Actions;10import org.openqa.selenium.JavascriptExecutor;11import org.openqa.selenium.Alert;12import org.openqa.selenium.support.ui.Select;13import java.io.IOException;14import java.io.File;15import java.io.FileInputStream;16import java.io.FileOutputStream;17import org.apache.poi.xssf.usermodel.XSSFWorkbook;18import org.apache.poi.xssf.usermodel.XSSFSheet;19import org.apache.poi.xssf.usermodel.XSSFRow;20import org.apache.poi.xssf.usermodel.XSSFCell;21import org.apache.poi.xssf.usermodel.XSSFFont;22import org.apache.poi.xssf.usermodel.XSSFCellStyle;23import java.util.Iterator;24import java.util.List;

Full Screen

Full Screen

WebDriverException

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriverException;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeDriver;4import org.openqa.selenium.firefox.FirefoxDriver;5import org.openqa.selenium.ie.InternetExplorerDriver;6import org.openqa.selenium.edge.EdgeDriver;7import org.openqa.selenium.opera.OperaDriver;8import org.openqa.selenium.remote.DesiredCapabilities;9import org.openqa.selenium.safari.SafariDriver;10import org.openqa.selenium.remote.RemoteWebDriver;11import java.net.URL;12import java.util.Scanner;13import java.util.concurrent.TimeUnit;14import java.io.File;15public class WebDriverFactory {16 public static WebDriver getDriver(String browser) {17 WebDriver driver = null;18 String os = System.getProperty("os.name").toLowerCase();19 String driverPath = null;20 if (os.contains("win")) {21 driverPath = "src\\test\\resources\\drivers\\";22 } else if (os.contains("mac")) {23 driverPath = "src/test/resources/drivers/";24 }25 try {26 switch (browser) {27 System.setProperty("webdriver.chrome.driver", driverPath + "chromedriver");28 driver = new ChromeDriver();29 break;30 System.setProperty("webdriver.gecko.driver", driverPath + "geckodriver");31 driver = new FirefoxDriver();32 break;33 System.setProperty("webdriver.ie.driver", driverPath + "IEDriverServer.exe");34 driver = new InternetExplorerDriver();35 break;36 System.setProperty("webdriver.edge.driver", driverPath + "MicrosoftWebDriver.exe");37 driver = new EdgeDriver();38 break;39 System.setProperty("webdriver.opera.driver", driverPath + "operadriver");40 driver = new OperaDriver();41 break;42 driver = new SafariDriver();43 break;44 System.out.println("Browser is not correct");45 break;46 }47 } catch (WebDriverException e) {48 System.out.println(e.getMessage());49 }50 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);51 return driver;52 }53 public static WebDriver getDriver(String browser, String nodeURL) {54 WebDriver driver = null;55 String driverPath = null;56 String os = System.getProperty("os.name").toLowerCase();

Full Screen

Full Screen

WebDriverException

Using AI Code Generation

copy

Full Screen

1package com.selenium4beginners.java.webdriver;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebDriverException;4import org.openqa.selenium.chrome.ChromeDriver;5public class WebDriverExceptionExample {6 public static void main(String[] args) {7 WebDriver driver = null;8 try {9 driver = new ChromeDriver();10 } catch (WebDriverException e) {11 System.out.println("Exception: " + e);12 } finally {13 driver.quit();14 }15 }16}17 (unknown error: DevToolsActivePort file doesn't exist)18 (The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)19 (Driver info: chromedriver=2.40.565383 (8a06a1883c3e0b3a67b1e8c3b6e53e0b9f6d2428),platform=Windows NT 10.0.19041 x86_64) (WARNING: The server did not provide any stacktrace information)

Full Screen

Full Screen

WebDriverException

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriverException;2public class WebDriverExceptionDemo {3 public static void main(String[] args) {4 try {5 throw new WebDriverException("WebDriverException Occured");6 }7 catch(WebDriverException e) {8 System.out.println(e.getMessage());9 }10 }11}

Full Screen

Full Screen

WebDriverException

Using AI Code Generation

copy

Full Screen

1package Selenium;2import org.openqa.selenium.*;3import org.openqa.selenium.firefox.FirefoxDriver;4public class SeleniumDemo {5public static void main(String[] args) {6WebDriver driver = new FirefoxDriver();7WebElement element = driver.findElement(By.name("q"));8element.sendKeys("Selenium");9element.submit();10System.out.println("Page title is: " + driver.getTitle());11driver.quit();12}13}

Full Screen

Full Screen

WebDriverException

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriverException; 2public class Test { 3public static void main(String[] args) { 4throw new WebDriverException(“Error Message”); 5} 6}7import org.openqa.selenium.WebDriverException; 8public class Test { 9public static void main(String[] args) { 10throw new WebDriverException(“Error Message”); 11} 12}13import org.openqa.selenium.WebDriverException; 14public class Test { 15public static void main(String[] args) { 16throw new WebDriverException(“Error Message”); 17} 18}19import org.openqa.selenium.WebDriverException; 20public class Test { 21public static void main(String[] args) { 22throw new WebDriverException(“Error Message”); 23} 24}25import org.openqa.selenium.WebDriverException; 26public class Test { 27public static void main(String[] args) { 28throw new WebDriverException(“Error Message”); 29} 30}31import org.openqa.selenium.WebDriverException; 32public class Test { 33public static void main(String[] args) { 34throw new WebDriverException(“Error Message”); 35} 36}37import org.openqa.selenium.WebDriverException; 38public class Test { 39public static void main(String[] args) { 40throw new WebDriverException(“Error Message”); 41} 42}43import org.openqa.selenium.WebDriverException; 44public class Test { 45public static void main(String[] args) { 46throw new WebDriverException(“Error Message”); 47} 48}49import org.openqa.selenium.WebDriverException;

Full Screen

Full Screen
copy
1 @Column(name="testname") //all small-case2
Full Screen
copy
1@Column(name="TestName")2public String getTestName(){//.........3
Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful