我正在尝试构建将转到网站“https://testmysite.thinkwithgoogle.com”的代码,在搜索字段中输入一个字符串,然后提交按钮以获取结果(我最终会抓取并保存在我的Excel中文件)。
但是,我无法提交按钮。我尝试过的任何迭代都会导致提交我输入文本后出现的删除文本X.以下是我的代码:
Sub GetScores()
Dim bot As New WebDriver
' URL to get data from
bot.Start "Chrome", "https://testmysite.thinkwithgoogle.com"
bot.Get "/"
' Eventually loop through websites, for now just use example
Dim str As String
str = "www.google.com"
'Paste str into webpage
bot.FindElementByName("pagespeed-input").SendKeys (str)
bot.FindElementByClass("pagespeed__submit").Submit
以下是该网站的HTML代码:
<div class="pagespeed " data-component="PageSpeed" >
<form class="pagespeed__form" action="">
<input type="hidden" name="pagespeed-locale" id="" value="en_us">
<input type="url" name="pagespeed-input" class="pagespeed__input" placeholder="Enter your website URL" tabindex="-1" autofocus >
<button type="submit" class="pagespeed__submit pagespeed__submit--disabled" data-gtm-id="smbhub-url-entry" disabled>Test now</button>
</form>
<div class='pagespeed__error'></div>
</div>
答案 0 :(得分:0)
尝试
bot.FindElementByXPath("//button[@type='submit']").Click
而不是使用
bot.FindElementByClass("pagespeed__submit").Submit