首页 > 解决方案 > 基本硒无法按类查找元素

问题描述

我正在尝试使用 BasicSelenium, Selenium for VBA 在门户网站中填写电话号码,但即使元素已加载,Selenium 也无法找到文本框

我的代码

Sub FillPhoneNumbers()


Set ch = New Selenium.ChromeDriver

ch.Start
ch.Get "https://nestlemedconnect.com/p/38ZX1SBcKhI"

ch.FindElementByClass("checkbox_label").Click
ch.FindElementByClass("accept_button").Click
ch.FindElementByCss(".left_button_inner.generic_menu_button.ti-comments-smiley").Click
ch.Wait (30)
ch.FindElementByClass("phonemask").SendKeys "122525" ' <- line that errors
End Sub 

而我试图填充的元素

<input class="phonemask" type="tel" name="phoneNumber" autocomplete="off" data-intl-tel-input-id="0" style="padding-left: 74px;" placeholder="201-555-0123"> 

我尝试使用该名称,但也没有用,我得到的只是 Web 驱动程序无法找到 elemet 错误

我究竟做错了什么?

标签: htmlvbaselenium

解决方案


因为您需要先单击此 Web 元素退出 SMS

div.ui.bottom.attached.button.optout.triggerform

做这个 :

ch.FindElementByCss("div.ui.bottom.attached.button.optout.triggerform").Click
ch.Wait (30)
ch.FindElementByClass("phonemask").SendKeys "122525

推荐阅读