【问题标题】:Unable to scroll down the calendar while automate the Yatra.com (Selenium webdriver using python)自动化 Yatra.com 时无法向下滚动日历(使用 python 的 Selenium webdriver)
【发布时间】:2017-10-12 07:05:15
【问题描述】:

我尝试自动化 Yatra 网站,但在选择日历中的值时卡住了。我无法向下滚动日历。

Website

Image

【问题讨论】:

标签: python selenium selenium-webdriver webdriver


【解决方案1】:

你可以在python中这样使用:

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

【讨论】:

    【解决方案2】:

    如果您试图通过向下滚动来定位某个元素,则以下代码将滚动直到该元素出现在视图中。

    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
    

    【讨论】:

    • 向他人索取代码时要更加尊重@SaniketA.Soni
    猜你喜欢
    • 1970-01-01
    • 2016-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    • 2013-04-14
    相关资源
    最近更新 更多