0

I have the following code written in Java with Selenium Webdriver, but it's not clicking the div with the star rating

driver.get("https://goo.gl/maps/gLCX3PitJT1cXr9v9");
driver.findElement(By.xpath("//button[@data-value=\"Escribir una opinión\"]")).click();
driver.switchTo().frame(2);
driver.findElement(By.xpath("//textarea")).sendKeys("This is just a test");
driver.findElement(By.xpath("//span[@aria-label=\"Cuatro estrellas\"]")).click();

Between each line, I also added a Thread.sleep(5000) just to ensure the page fully loads.

The only clear identifier that I see is the aria-label.

Full HTML

Manual steps:

  • Open URL: https://goo.gl/maps/gLCX3PitJT1cXr9v9
  • Click "Escribir una opinión" or "Write a review" button
  • Type in the review field: "This is just a test"
  • Select the star rating: 4 stars
  • Click "Publicar" or "Post" (or Publish)
JohnP
  • 33
  • 6

3 Answers3

0

The Xpath for the "four-star" element is wrong. It should be //div[@aria-label='Cuatro estrellas']. You had span instead.

hfontanez
  • 5,774
  • 2
  • 25
  • 37
0

Can you try below

driver.findElement(By.xpath("//div[@class="s2xyy"][4]")).click();

OR

driver.findElement(By.xpath("//div[@role="radio"][3]")).click();

it is working for me enter image description here

0

To click() on star rating 4 stars as the the desired element is within a <iframe> so you have to:

  • Induce WebDriverWait for the desired frameToBeAvailableAndSwitchToIt.
  • Induce WebDriverWait for the desired elementToBeClickable.
  • You can use either of the following Locator Strategies:
    • Using cssSelector:

      new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe.goog-reviews-write-widget")));
      new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[aria-label='Four stars']"))).click();
      
    • Using xpath:

      new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@class='goog-reviews-write-widget']")));
      new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@aria-label='Four stars']"))).click();
      

Reference

You can find a couple of relevant discussions in:

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