如何在Tripadvisor.in中使用Selenium和Java处理气泡等级窗口小部件中的等级

问题描述 投票:0回答:1

我有一种情况,我需要单击tripadvisor中的气泡评分小部件的第五个气泡

HTML代码是:

<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>

我正在尝试以下代码片段:

Actions action = new Actions(driver);
WebElement element = driver.findElement(By.xpath("//span[@id='bubble_rating']"));
action.moveToElement(element).perform();

此代码仅悬停第三个气泡,其余第4、5个气泡未被单击。

java selenium xpath css-selectors tripadvisor
1个回答
0
投票

要使用https://www.tripadvisor.in/单击Selenium气泡等级小部件内的所有5星级,您必须为visibilityOfElementLocated()引入WebDriverWait,并且可以使用以下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();
    
  • 浏览器快照:

bubble_rating_widget

© www.soinside.com 2019 - 2024. All rights reserved.