Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.genericlibrary;
- import java.util.List;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.openqa.selenium.support.ui.ExpectedConditions;
- import org.openqa.selenium.support.ui.Select;
- import org.openqa.selenium.support.ui.WebDriverWait;
- import com.util.Highlighter;
- public class MobopsSearchJobsFromDropDown {
- WebDriver driver;
- Highlighter color;
- public void getSetup() {
- String path = System.getProperty("user.dir");
- String driverPath = path + "\Driver\chromedriver.exe";
- System.setProperty("webdriver.chrome.driver", driverPath);
- driver = new ChromeDriver();
- driver.navigate().to("http://mobops-test.jcdecauxna.com/");
- driver.manage().window().maximize();
- }
- public void logIntoMobops() {
- WebElement userName = driver.findElement(By.xpath("//*[contains(@id,'username')]"));
- WebElement passWord = driver.findElement(By.xpath("//*[contains(@id,'password')]"));
- WebElement loginButton = driver.findElement(By.xpath("//*[contains(text(),'Login')]"));
- userName.sendKeys("test2");
- passWord.sendKeys("1234");
- loginButton.click();
- }
- public void selectEachPropertyAndSeachJob() {
- WebElement dateRange = driver.findElement(By.xpath("//*[contains(@name,'date_range')]"));
- WebElement last7days = driver.findElement(By.xpath("(//*[contains(text(),'Last 7 Days')])[2]"));
- WebElement searchJobs = driver.findElement(By.xpath("//*[contains(@name,'layout')]"));
- WebElement propertyDropdown = driver.findElement(By.xpath("//*[contains(@id,'property_id')]"));
- Select dropdown = new Select(propertyDropdown);
- List<WebElement> optionsInPropertyDropdown = dropdown.getOptions();
- for (int i = 0; i < optionsInPropertyDropdown.size(); i++) {
- if (propertyDropdown.isDisplayed() && propertyDropdown.isEnabled()) {
- try {
- propertyDropdown.click();
- dropdown.selectByVisibleText(optionsInPropertyDropdown.get(i).getText());
- dateRange.click();
- last7days.click();
- searchJobs.click();
- System.out.println("Option Search is " + optionsInPropertyDropdown.get(i).getText());
- } catch (org.openqa.selenium.StaleElementReferenceException ex) {
- WebDriverWait wait = new WebDriverWait(driver, 30);
- wait.until(ExpectedConditions.visibilityOf(propertyDropdown));
- }
- }
- }
- }
- public static void main(String[] args) {
- MobopsSearchJobsFromDropDown obj = new MobopsSearchJobsFromDropDown();
- obj.getSetup();
- obj.logIntoMobops();
- obj.selectEachPropertyAndSeachJob();
- }
- }
- Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
- new WebDriverWait(driver, timeout)
- .ignoring(StaleElementReferenceException.class)
- .until((WebDriver d) -> {
- d.findElement(By.xpath("//*[contains(@id,'property_id')]")).click();
- return true;
- });
Add Comment
Please, Sign In to add comment