2017-02-15 1 views
0

Könnten Sie mir bitte helfen, ein Element in webdriver für die Suche:Selen WebDriver Automatisch-Bestücken Wert von Dropdown

  1. Angenommen, wir haben zwei Dropdown-Menü ist Client und zweite Anlage. Ohne Auswahl des Clients können wir die Einrichtung nicht als deaktiviert auswählen.
  2. Wir haben Client-Wert aus Dropdown ausgewählt.
  3. Jetzt habe ich ein Skript für einen neuen Tab geschrieben.
  4. Danach muss ich Facility-Feld durch ID finden, aber es zeigt Element wird nicht gefunden, dann könnten Sie mir bitte für das gleiche helfen? .. Angehängt ist der Screenshot für Ihre Referenz. enter image description here Könnten Sie bitte überprüfen?
+2

Können Sie Seite 'URL' oder Drop-Down teilen' HTML' ? – Andersson

Antwort

0

mit vorheriger Frage Weiter Select options from Autopopulate text boxes using Selenium webdriver


Wenn Sie gleiches cssSelector zweites Mal verwenden, sucht er zunächst Drop-Down-Element, das zu diesem Zeitpunkt nicht sichtbar ist. Sie müssen spezifischere Locator, wie unten mit Beschriftungstext verwendet werden: -

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() 

Vollarbeitsbeispielcode: -

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("[email protected]"); 
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("password"))).sendKeys("[email protected]"); 
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();