Skip to content

Instantly share code, notes, and snippets.

@dejanvasic85
Last active July 31, 2017 11:56
Show Gist options
  • Save dejanvasic85/e838d8434899852b32474a31246b89e1 to your computer and use it in GitHub Desktop.
Save dejanvasic85/e838d8434899852b32474a31246b89e1 to your computer and use it in GitHub Desktop.
Selenium WebDriver with Google GeoComplete
public BookingEventStep WithLocation(string location)
{
_webdriver.ScrollElementToMiddle(LocationInput);
LocationInput.FillText(location);
var wait = new WebDriverWait(_webdriver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementToBeClickable(By.ClassName("pac-item")));
LocationInput.SendKeys(Keys.ArrowDown);
LocationInput.SendKeys(Keys.ArrowDown);
LocationInput.SendKeys(Keys.Enter);
return this;
}
public BookingEventStep WithLocation(string location)
{
_webdriver.ScrollElementToMiddle(LocationInput);
LocationInput.FillText(location);
var wait = new WebDriverWait(_webdriver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementIsVisible(By.ClassName("pac-container")));
var googleAddressResults = _webdriver.FindElements(By.ClassName("pac-item"));
if (googleAddressResults.Count == 0)
{
throw new NoSuchElementException("Geolocation cannot find the address " + location);
}
//_webdriver.JsClick(googleAddressResults.First());
googleAddressResults.First().Click();
return this;
}
<package id="Dapper" version="1.13" targetFramework="net45" />
<package id="Monads" version="1.1.5.0" targetFramework="net45" />
<package id="NUnit" version="2.6.3" targetFramework="net45" />
<package id="Selenium.Support" version="3.3.0" targetFramework="net461" />
<package id="Selenium.WebDriver" version="3.4.0" targetFramework="net461" />
<package id="SpecFlow" version="1.9.0" targetFramework="net45" />
<package id="SpecFlow.NUnit" version="1.1.1" targetFramework="net45" />
<package id="WebDriver.GeckoDriver" version="0.16.0" targetFramework="net461" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment