Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何单击日期选择器selenium VBA?_Vba_Selenium_Selenium Webdriver_Web Scraping - Fatal编程技术网

如何单击日期选择器selenium VBA?

如何单击日期选择器selenium VBA?,vba,selenium,selenium-webdriver,web-scraping,Vba,Selenium,Selenium Webdriver,Web Scraping,我想使用selenium VBA从中下载一些数据 当我点击日期选择器箭头以获得小窗口来选择今天的结束日期时,我遇到了困难。我试图在chrome中通过selenium IDE记录marco,但当我单击时间段的箭头以使日期选择器可见时,IDE没有记录该步骤 下面是我在VBA中的代码 Public Function seleniumKorea(bot As WebDriver) Dim url As String url = "https://finance.yahoo.com/quo

我想使用selenium VBA从中下载一些数据

当我点击日期选择器箭头以获得小窗口来选择今天的结束日期时,我遇到了困难。我试图在chrome中通过selenium IDE记录marco,但当我单击时间段的箭头以使日期选择器可见时,IDE没有记录该步骤

下面是我在VBA中的代码

Public Function seleniumKorea(bot As WebDriver)
    Dim url As String
    url = "https://finance.yahoo.com/quote/%5EKS11/history?period1=1484018309&period2=1515554309&interval=1d&filter=history&frequency=1d"
    bot.Start "chrome", url
    bot.Get "/"

    'Not sure how to add date picker here        
    bot.FindElementByName("endDate").Clear
    bot.FindElementByName("endDate").SendKeys (Date)
    bot.FindElementByXPath("(.//*[normalize-space(text()) and normalize-space(.)='End Date'])[1]/following::button[1]").Click

    Application.Wait (Now + TimeValue("0:01:00"))

    bot.FindElementByXPath("(.//*[normalize-space(text()) and normalize-space(.)='As of'])[1]/following::div[4]").Click
    Application.Wait (Now + TimeValue("0:01:00"))
    bot.FindElementByXPath("(.//*[normalize-space(text()) and normalize-space(.)='Currency in KRW'])[1]/following::span[2]").Click

    Application.Wait (Now + TimeValue("0:01:00"))
End Function    
我尝试使用ByXPath获取svg类,但失败了


提前感谢。

我将使用以下命令,如果需要,提交宣誓同意书,并将日期选择器滚动到视口中

Option Explicit
Public Sub DatePicking()
    Dim d As WebDriver
    Set d = New ChromeDriver
    Const URL = "https://finance.yahoo.com/quote/%5EKS11/history?period1=1484018309&period2=1515554309&interval=1d&filter=history&frequency=1d/"

    With d
        .get URL
        If .Title = "Yahoo is now part of Oath" Then
            .FindElementByCss("form").submit
        End If

        With .FindElementByCss("[data-test='date-picker-full-range']")
            .ScrollIntoView
            .Click
        End With
        With .FindElementByCss("[name=startDate]")
            .Clear
            .SendKeys "05/10/2017"
        End With

        With .FindElementByCss("[name=endDate]")
            .Clear
            .SendKeys "05/10/2017"
        End With
        Stop                                     '<==Delete me later
        .Quit
    End With
End Sub
选项显式
公共子日期选取()
dimdaswebdriver
设置d=新的色度驱动器
常量URL=”https://finance.yahoo.com/quote/%5EKS11/history?period1=1484018309&period2=1515554309&interval=1d&filter=history&frequency=1d/"
与d
.获取URL
如果.Title=“雅虎现在是誓言的一部分”,那么
.FindElementByCss(“表格”)。提交
如果结束
使用.FindElementByCss(“[data test='date-picker-full-range']”)
.ScrollIntoView
点击
以
使用.FindElementByCss(“[name=startDate]”)
清楚的
.SendKeys“2017年10月5日”
以
带.FindElementByCss(“[name=endDate]”)
清楚的
.SendKeys“2017年10月5日”
以

停下来看看这个。它应该达到目的。我使用了
xpath
来解决这个问题

Sub CustomizeDate()
    Const Url$ = "https://finance.yahoo.com/quote/%5EKS11/history?period1=1484018309&period2=1515554309&interval=1d&filter=history&frequency=1d"
    Dim driver As New ChromeDriver

    With driver
        .get Url
        .FindElementByXPath("//input[@data-test='date-picker-full-range']", timeout:=5000).Click
        .FindElementByXPath("//input[@name='startDate']").Clear.SendKeys ("01/05/2017")
        .FindElementByXPath("//input[@name='endDate']").Clear.SendKeys ("01/08/2017")
        .FindElementByXPath("//button/span[.='Done']", timeout:=5000).Click
        .FindElementByXPath("//button/span[.='Apply']", timeout:=5000).Click
    End With
End Sub

不要使用硬编码延迟来显示任何项目。改为使用显式等待。脚本将等待多达5000次,这意味着该项目需要5秒时间。

谢谢。你的方法很有效,但我需要在输入正确的日期后单击“完成”按钮。我尝试了上面提到的方法。
使用.FindElementByCss(“[name=Done]”)。单击End With
失败。请问如何点击数据选择器上的“完成”按钮。恐怕我没有收到这条消息,所以我的回答与您的要求完全一致。很抱歉但SIM已经为您提供了该部件。