Reputation: 103
So I have the following HTML Tag I want to fetch with Selenium:
<button data-v-48e2f75a="" class="app-button rose-button min-width">Sign in</button>
I am trying to fetch it like so:
...
browser.findElement(By.cssSelector("app-button rose-button min-width")).click();
When I run this it always returns the following exception:
org.openqa.selenium.NoSuchElementException: Unable to locate element: app-button rose-button min-width
This is one of the methods I've tried already however it has not worked either:
browser.findElement(By.cssSelector("app-button rose-button min-width")).click();
Upvotes: 0
Views: 458
Reputation: 125
The css selector is wrong. Try it in this way:
Upvotes: 2
Reputation: 3671
It should be By.className instead of cssSelector.
Example:
WebElement parentElement = driver.findElement(By.className("rose-button"));
If you want to use cssSelector, it should look like:
driver.findElement(By.cssSelector("button[class='app-button rose-button min-width']"));
Another way is using xpath:
driver.findElement(By.xpath("//div[@class='app-button rose-button min-width']"));
And as DebanjanB mentioned, you can add webdriverwait also, if there is some kind of loading delay.
Upvotes: 1
Reputation: 193338
To click on the element with text as Sign in you have to induce WebDriverWait for the elementToBeClickable()
and you can use either of the following Locator Strategies:
Using cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.app-button.rose-button.min-width"))).click();
Using xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='app-button rose-button min-width' and text()='Sign in']"))).click();
You can find a couple of detailed discussions in:
Upvotes: 0