SendKeys会将新文本添加到旧文本中,因此如何替换现有文本

问题描述

我绝不是程序员,我只是想在Excel工作簿中自动执行Chrome报表。

我正在使用VBA Selenium,需要将日期发送到文本字段。我用过FindElementByXPathFindElementByName都可以。

obj.FindElementByName("filter_date_start_sold").Click – works
obj.FindElementByName("filter_date_start_sold").Clear – works
obj.FindElementByName("filter_date_start_sold").SendKeys ("01/08/2018"). 

这可行,但是它将新日期添加到“文本字段”中已经列出的日期,因此它变为01/08/202001/08/2018

我尝试使用.SendKeys(Keys.Backspace),但Back Space函数将无法执行任何操作。

Sub ChromeAutoSYD()

Dim obj As New WebDriver
obj.Start "chrome",""

Set IE = CreateObject("InternetExplorer.Application")

Obj.Get "I am sorry  I cannot list the actual URL as it is a company DB Site"

'The Sheet reference is my login details and this all works well
obj.FindElementByName("username").SendKeys (ThisWorkbook.Sheets("Sheet3").Range("D20").Value)
obj.FindElementByName("password").SendKeys (ThisWorkbook.Sheets("Sheet3").Range("D21").Value)
obj.FindElementByXPath("/html/body/div/div/div/div/div/div/div[2]/form/div[3]/button").Click

obj.FindElementByXPath("/html/body/div[1]/div/div[2]/div/div[2]/div[3]/div[2]/div/div/input").SendKeys("01082018").Value

 obj.FindElementByXPath("/html/body/div[1]/div/div[2]/div/div[2]/div[3]/div[4]/button").Click
 
  Application.Wait (Now + TimeValue("0:00:05"))

End Sub

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)