【发布时间】:2021-09-02 04:50:53
【问题描述】:
我正在尝试找出列表中的第 5 个元素并单击它。
所有已存储房间的列表:
@FindBy(xpath="//p[@class='css-6v9gpl-Text eczcs4p0']")
List<WebElement> placeListings;
代码:
public void clickon5thHouse()
{
Web4 = placeListings.get(4); // **This is a list of all the webelements in <div> tag | I am picking 4th element from the list and trying to click on it**
int x = Web4.getLocation().getX();
int y = Web4.getLocation().getY();
//scroll to x y
JavascriptExecutor js = (JavascriptExecutor) driver;
WebDriverWait wait;
wait = new WebDriverWait(driver,40);
//((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", Web4);
//((JavascriptExecutor) driver).executeScript("window.scrollTo(0,document.documentElement.scrollHeight);");
js.executeScript("window.scrollBy(" +x +", " +y +")");
wait.until(ExpectedConditions.elementToBeClickable(Web4));
Web4.click();
//((JavascriptExecutor) driver).executeScript("arguments[0].click();", Web4);
}
- 使用 Chrome 浏览器。
- 尝试使用所有可能的滚动方法,您可以查看注释代码。
- 对于所有滚动命令,它只是滚动到网站中的同一点,我不确定我是否遗漏了任何内容。 Scrollbar is reaching till this point for all the scroll commands
错误日志:
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <p size="6" class="css-6v9gpl-Text eczcs4p0">...</p> is not clickable at point (845, 13).
Other element would receive the click: <a data-testid="listing-details-link" href="/for-sale/details/58485081/" class="e2uk8e4 css-15tydk8-StyledLink-Link-FullCardLink e33dvwd0">...</a>
【问题讨论】:
标签: javascript java selenium webdriver