Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. public WebElement findElement(String path, Pather type, TimeOut timeOut) {
  2.  
  3.  
  4.  
  5. try {
  6.  
  7. WebDriverWait wait = new WebDriverWait(driver, timeOut.value);
  8.  
  9. WebElement element = null;
  10.  
  11. switch (type) {
  12.  
  13. case className:
  14.  
  15. element = wait.until(ExpectedConditions.presenceOfElementLocated(By.className(path)));
  16.  
  17. break;
  18.  
  19. case id:
  20.  
  21. element = wait.until(ExpectedConditions.presenceOfElementLocated(By.id(path)));
  22.  
  23. break;
  24.  
  25. case name:
  26.  
  27. element = wait.until(ExpectedConditions.presenceOfElementLocated(By.name(path)));
  28.  
  29. break;
  30.  
  31. case xPath:
  32.  
  33. element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(path)));
  34.  
  35. break;
  36.  
  37. case cssSelector:
  38.  
  39. element = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(path)));
  40.  
  41. break;
  42.  
  43. case linkText:
  44.  
  45. element = wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText(path)));
  46.  
  47. break;
  48.  
  49. default:
  50.  
  51. new NotFoundException();
  52.  
  53. }
  54.  
  55. return element;
  56.  
  57. }
  58.  
  59. catch (Exception ex)
  60.  
  61. {
  62. return null;
  63.  
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement