0

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();
Aasil
  • 103
  • 5

3 Answers3

2

The css selector is wrong. Try it in this way:

  • browser.findElement(By.cssSelector(".app-button.rose-button.min-width")).click();
Ledjon
  • 105
  • 8
1

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.

Abhinaba Chakraborty
  • 3,488
  • 2
  • 16
  • 37
0

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

Reference

You can find a couple of detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352