我有一种情况,我需要单击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个气泡未被单击。
要使用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();
浏览器快照: