I am missing something very elementary. From all that I could collect, I think I need a list id that crashes as I type. As soon as I have an id , I think I can get the list and iterate over it.
AutoFill Web Code:
<div class="col-md-12"> <label>Google Map Location*</label> <input id="searchTextField" type="text" class="form-control" placeholder="Enter a location" autocomplete="on" required="required"> <input id="latitude" type="text" style="display: none;" class="form-control" value=""> <input id="longitude" type="text" style="display: none;"class="form-control" value=""> <p class="help-block" style="color: #737373;">Instruction: Please drag the marker to get exact location of the IT park.</p> </div>
javascript to initialize js code
var input = document.getElementById('searchTextField'); var autocomplete = new google.maps.places.Autocomplete(input); autocomplete.bindTo('bounds', map);
Selenium Code:
autocompleteElement = God.getWebElementById("searchTextField"); autocompleteElement.sendKeys("Airport"); List<WebElement> autoCompleteList = Initialize.getInstance().getDriver().findElements( By.className("form-control"); for (WebElement autocompleteItem : autoCompleteList) { if (autocompleteItem.getText().contains("Pune Airport")) { autocompleteItem.click(); } break; }
I get autocompleteItem empty or empty.
Change 1
I am new to javascript and I am inheriting this code base. I donβt understand how to assign a locator container OR a id so that I can iterate through WebElement and click on my desired result.
Edit 2
I added a snapshot of the autocomplete check item. The answers below relate to xpath ("something very complicated for me"). What can I replace xpath in my specific case?
OR
What do you need to help me get a dropdown list?

Edit 3
I used the class- form-control class name like this
List<WebElement> autoCompleteList = waitForElementByClass( "form-control"); System.out.println("autocomplete list size " + autoCompleteList.size()); for (WebElement autocompleteItem : autoCompleteList) { if (autocompleteItem.getText().contains("Wadgaon Sheri")) { System.out.println("auto complete selected " + autocompleteItem.getText()); autocompleteItem.click(); break; } else System.out.println("no match, tagname:" + autocompleteItem.getTagName() + "point:" + autocompleteItem.getLocation()); }
And got the following result. Note: autocompleteItem.getText returns an empty string.
autocomplete list size 16 no match, tagname:inputpoint:(255, 200) no match, tagname:selectpoint:(255, 274) no match, tagname:inputpoint:(255, 433) no match, tagname:selectpoint:(255, 509) no match, tagname:inputpoint:(255, 553) no match, tagname:inputpoint:(330, 553) no match, tagname:inputpoint:(255, 627) no match, tagname:textareapoint:(525, 200) no match, tagname:textareapoint:(525, 324) no match, tagname:inputpoint:(525, 450) no match, tagname:inputpoint:(525, 526) no match, tagname:inputpoint:(525, 602) no match, tagname:inputpoint:(525, 678) no match, tagname:inputpoint:(796, 200) no match, tagname:inputpoint:(0, 0) no match, tagname:inputpoint:(0, 0)
Now I try with the class name pac-container pac.logo , and then I try with div.pac-container.pac-logo too :). Remember my javascript skills are not too great.

Edit 4 Now I tried the class name as pac-container pac.logo , pac-container.pac-logo , div.pac-container.pac.logo and pac-container , the result
wait.until (ExpectedConditions.visibilityOfElementLocated (By.className (byclass)));
is that the code hangs here
If I replaced the string
wait.until (ExpectedConditions.elementToBeSelected (God.getWebElementByClassNae (byclass)));
I get a NoElementFoundException .
So, my closest bet on solving this problem is to find the class name of the damned drop-down list.
public List<WebElement> waitForElementByClass(String byclass) { WebDriverWait wait = new WebDriverWait(God.getCurrentBrowser(), 2000); List<WebElement> elements = null; boolean waitForElement = true; System.out.print("Waiting for " + byclass); do { System.out.print("."); try { //wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(byclass))); wait.until(ExpectedConditions.elementToBeSelected(God.getWebElementByClassNae(byclass))); waitForElement = false; System.out.println("found"); elements = God.getWebElementsByClassName(byclass); } catch (NoSuchElementException e) { waitForElement = true; } catch (TimeoutException e) { waitForElement = false; return null; } } while (waitForElement); return elements; }