0

Could you please help me for finding an element in webdriver:

  1. Suppose we have two drop downs one is client and second facility. Also, without selecting client we cannot select facility as its disabled.
  2. We've selected client value from drop down.
  3. Now I've written a script for a new tab.
  4. After that, I've to find facility field through ID but it shows element is not found, then could you please help me for the same? .. Attached is the screen shot for your reference.enter image description here Could you please check?
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
ajay kumar
  • 73
  • 1
  • 9

1 Answers1

0

Continue with previous question Select options from Autopopulate text boxes using Selenium webdriver


When you are using same cssSelector second time, it locates first dropdown element which is invisible at that time. you need to use more specific locator as below using label text :-

WebElement facility = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("facility")))
facility.sendKeys("Ho")

List<WebElement> facilityOptions = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(".//div[label[text() = 'Ordering Location']]/ul[@class = 'typeahead dropdown-menu']//a")))
facilityOptions.get(0).click()

Full working example code :-

driver.get("https://bioceptbetaweb.azurewebsites.net/Account/Login");
driver.manage().window().maximize()

WebDriverWait wait = new WebDriverWait(driver, 60)

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username"))).sendKeys("ajay.kumar@technossus.com");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("password"))).sendKeys("Ajay@123");
wait.until(ExpectedConditions.elementToBeClickable(By.id("btn-Login"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Place a New Order"))).click();

wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("loaderDiv")));


//this sleep is required because after invisibility of loader focus goes to first input which is Requisition Number
//If you are filling form from first input no need to for this sleep
//if you want to input directly to client field need to sleep to avoid focus first      
Thread.sleep(3000);


WebElement client = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("client")));
client.sendKeys("Ho");

List<WebElement> dropdownOptions = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(".//div[label[text() = 'Client']]/ul[@class = 'typeahead dropdown-menu']//a")));
dropdownOptions.get(0).click();

WebElement facility = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("facility")));
facility.sendKeys("Ho");

List<WebElement> facilityOptions = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(".//div[label[text() = 'Ordering Location']]/ul[@class = 'typeahead dropdown-menu']//a")));
facilityOptions.get(0).click();
Community
  • 1
  • 1
Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73