I hava a scenario in which i need to click fifth bubble of bubble rating widget within tripadvisor
The HTML code is:
<span id="bubble_rating" class="ui_bubble_rating fl bubble_10" data-value="1" onclick="ta.userreview.common.trackFieldFocus(this); ">
<img src="https://static.tacdn.com/img2/x.gif" alt="Roll over, then click to rate">
</span>
I am trying with below code snippet:
Actions action = new Actions(driver);
WebElement element = driver.findElement(By.xpath("//span[@id='bubble_rating']"));
action.moveToElement(element).perform();
This code hovers only first 3 bubbles and rest 4th,5th are not being clicked.
To click for all the 5 star ratings within the Bubble Rating widget in https://www.tripadvisor.in/ using Selenium you have to induce WebDriverWait for the visibilityOfElementLocated()
and you can use either of the following Locator Strategies:
cssSelector
:
driver.get("https://www.tripadvisor.in/UserReviewEdit-g641714-d1156207-Club_Mahindra_Madikeri_Coorg-Madikeri_Kodagu_Coorg_Karnataka.html]");
new Actions(driver).moveToElement(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("span#bubble_rating"))), 50, 0).click().build().perform();
xpath
:
driver.get("https://www.tripadvisor.in/UserReviewEdit-g641714-d1156207-Club_Mahindra_Madikeri_Coorg-Madikeri_Kodagu_Coorg_Karnataka.html]");
new Actions(driver).moveToElement(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='bubble_rating']"))), 50, 0).click().build().perform();
Browser Snapshot: