Guest User

Untitled

a guest
Nov 20th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. package com.genericlibrary;
  2.  
  3. import java.util.List;
  4.  
  5. import org.openqa.selenium.By;
  6. import org.openqa.selenium.WebDriver;
  7. import org.openqa.selenium.WebElement;
  8. import org.openqa.selenium.chrome.ChromeDriver;
  9. import org.openqa.selenium.support.ui.ExpectedConditions;
  10. import org.openqa.selenium.support.ui.Select;
  11. import org.openqa.selenium.support.ui.WebDriverWait;
  12.  
  13. import com.util.Highlighter;
  14.  
  15. public class MobopsSearchJobsFromDropDown {
  16.  
  17. WebDriver driver;
  18. Highlighter color;
  19.  
  20. public void getSetup() {
  21. String path = System.getProperty("user.dir");
  22. String driverPath = path + "\Driver\chromedriver.exe";
  23. System.setProperty("webdriver.chrome.driver", driverPath);
  24. driver = new ChromeDriver();
  25. driver.navigate().to("http://mobops-test.jcdecauxna.com/");
  26. driver.manage().window().maximize();
  27. }
  28.  
  29. public void logIntoMobops() {
  30. WebElement userName = driver.findElement(By.xpath("//*[contains(@id,'username')]"));
  31. WebElement passWord = driver.findElement(By.xpath("//*[contains(@id,'password')]"));
  32. WebElement loginButton = driver.findElement(By.xpath("//*[contains(text(),'Login')]"));
  33.  
  34. userName.sendKeys("test2");
  35. passWord.sendKeys("1234");
  36. loginButton.click();
  37.  
  38. }
  39.  
  40. public void selectEachPropertyAndSeachJob() {
  41. WebElement dateRange = driver.findElement(By.xpath("//*[contains(@name,'date_range')]"));
  42. WebElement last7days = driver.findElement(By.xpath("(//*[contains(text(),'Last 7 Days')])[2]"));
  43. WebElement searchJobs = driver.findElement(By.xpath("//*[contains(@name,'layout')]"));
  44. WebElement propertyDropdown = driver.findElement(By.xpath("//*[contains(@id,'property_id')]"));
  45.  
  46. Select dropdown = new Select(propertyDropdown);
  47.  
  48. List<WebElement> optionsInPropertyDropdown = dropdown.getOptions();
  49. for (int i = 0; i < optionsInPropertyDropdown.size(); i++) {
  50. if (propertyDropdown.isDisplayed() && propertyDropdown.isEnabled()) {
  51. try {
  52. propertyDropdown.click();
  53. dropdown.selectByVisibleText(optionsInPropertyDropdown.get(i).getText());
  54. dateRange.click();
  55. last7days.click();
  56. searchJobs.click();
  57. System.out.println("Option Search is " + optionsInPropertyDropdown.get(i).getText());
  58.  
  59. } catch (org.openqa.selenium.StaleElementReferenceException ex) {
  60. WebDriverWait wait = new WebDriverWait(driver, 30);
  61. wait.until(ExpectedConditions.visibilityOf(propertyDropdown));
  62. }
  63. }
  64.  
  65. }
  66.  
  67. }
  68.  
  69. public static void main(String[] args) {
  70.  
  71. MobopsSearchJobsFromDropDown obj = new MobopsSearchJobsFromDropDown();
  72. obj.getSetup();
  73. obj.logIntoMobops();
  74. obj.selectEachPropertyAndSeachJob();
  75.  
  76. }
  77. }
  78.  
  79. Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
  80.  
  81. new WebDriverWait(driver, timeout)
  82. .ignoring(StaleElementReferenceException.class)
  83. .until((WebDriver d) -> {
  84. d.findElement(By.xpath("//*[contains(@id,'property_id')]")).click();
  85. return true;
  86. });
Add Comment
Please, Sign In to add comment