Reputation: 36656
public static void main(String[] args) {
{
System.setProperty("webdriver.chrome.driver", "/Users/me/selenium-2.53.1/chromedriver");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--incognito"));
WebDriver driver = new ChromeDriver(capabilities);
driver.get("http://www/.google.com");
WebElement el = driver.findElement(By.id("#myButton"));
el.click();
driver.close();
}
driver.quit();
}
}
However my code never returns from driver.findElement(By.id("#myButton"));
not even returning a null element
How can i fix this?
Upvotes: 0
Views: 42
Reputation: 23805
#myButton
will work with By.cssSelector()
.. if you want to locate element using By.id()
, no need to append #
try as below:-
WebElement el = driver.findElement(By.id("myButton"));
Hope it helps...:)
Upvotes: 1
Reputation: 473803
You would use #myButton
with a By.cssSelector()
locator:
WebElement el = driver.findElement(By.cssSelector("#myButton"));
In case of By.id()
omit the #
:
WebElement el = driver.findElement(By.id("myButton"));
Upvotes: 0