简体   繁体   English

在自动化 Yatra.com 时无法向下滚动日历(使用 Python 的 Selenium webdriver)

[英]Unable to scroll down the calendar while automate the Yatra.com (Selenium webdriver using python)

I tried to automate the Yatra website but got stuck while selecting the values in the calendar.我试图自动化 Yatra 网站,但在选择日历中的值时卡住了。 I am not able to scroll down the calendar.我无法向下滚动日历。

Website网站

Image图片

If you are trying to locate some element by scrolling down, the following code will scroll until the element is in view.如果您试图通过向下滚动来定位某个元素,以下代码将滚动直到该元素出现在视图中。

WebElement element = driver.findElement(By.xpath("//div[@id='PegasusCal-0']//div[@class='cal-body']"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
Thread.sleep(500); 

//do anything you want with the element

You can use like this in python:你可以在 python 中这样使用:

element = driver.find_element_by_xpath("your xpath")
driver.execute_script("arguments[0].scrollIntoView();", element)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM