【发布时间】:2020-07-09 18:37:16
【问题描述】:
我是论坛的新手,有一些 VBA 经验,但不是很多。
我正在使用 Selenium 促进与 Chrome 网站的交互,目的是使用 Excel 电子表格中的数据自动向该网站发出一系列请求(Starleaf Web 会议)。
我可以正常登录,并且可以使用FindElementByID 和FindElementByTag("a").Click 语句在页面之间导航。
我在使用这种方法在一页上导航时遇到问题。我试过ByID(the first 2 IDs in the code below),ByLinkText,ByClass (portalContent, button, single),ByCssSelector;但没有任何效果。此表格的代码行上的宏停顿:
Set elem = bot.FindElementBy*****("Parameter")
elem.FindElementByTag("a").Click
相关页面上的代码是:
<div class="portalContent">
<div id="viewConferencesAddDiv" class="buttons single" style="">
<a id="viewConferences_add" href="https://portal.starleaf.com/#page=addUserConference" target="_parent">
<span id="viewConferences_add_text">Schedule meeting</span>
</a>
</div>
我想知道“a”标签和 href 之间的 id="viewConferences_add" 是否有问题,但我不知道如何解决这个问题。
我尝试使用的另一种方法是在登录后直接转到我需要的页面,但这似乎不起作用。我可能有语法问题???
这是我尝试过的:
bot.Get "/#page=addUserConference"
bot.Get "https://portal.starleaf.com/#page=addUserConference"
bot.Get "//portal.starleaf.com/#page=addUserConference"
之后使用此代码为页面加载留出时间:
Do Until InStr(1, bot.Url, "addUserConference") > 0
Application.Wait (DateAdd("s", 1, Now))
DoEvents
Loop
更新
我环顾四周,发现有人在谈论 iframe 切换。查看 F12 中的页面,实际上看起来“安排会议”按钮可能位于 iframe 中。建议是切换到 if 但是我不知道该怎么做。页面上似乎有几个 iframe - 所以我想我需要 ID。我想可能是 id=mainPanel_iframe。
iframe 标签的 HTML:
<iframe id="mainPanel_iframe" name="mainPanel_iframe" class="mochaIframe" src="https://portal.starleaf.com/pbx/node-1.live.pr.starleaf.com/portal/#page=users&lang=en_int" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto" style="height: 579px; width: 1543px;"></iframe>
【问题讨论】:
-
您是否收到错误消息?如果是这样,是什么?您是否检查过该元素不在框架/iframe 父级中?
-
@QHarr 你是对的。现在在 iframe 中我只能在错误前执行一个 `bot.FindElement SendKeys:
bot.Wait 5000 bot.SwitchToFrame "mainPanel_iframe" bot.Wait 5000 bot.FindElementById("editConference_label").SendKeys "Test Jonathan" bot.FindElementById("editConference_start").SendKeys "30/03/2020" bot.FindElementById("editConference_startTime").SendKeys "17:00" bot.FindElementById("editConference_end").SendKeys "30/03/2020" bot.FindElementById("editConference_endTime").SendKeys "18:00"
标签: excel vba selenium xpath iframe