我有一个场景,我需要单击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();
此代码仅悬停前 3 个气泡,其余 4 个、第 5 个气泡不会被单击。
最佳答案
点击 https://www.tripadvisor.in/ 中的气泡评级小部件中的所有5星级评级使用Selenium您必须为 visibilityOfElementLocated()
引发WebDriverWait,并且您可以使用以下任一 Locator Strategies :
css选择器
: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();
浏览器快照:
关于java - 如何在 Tripadvisor 中处理气泡评分小部件内的评分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60112493/