【问题标题】:How to click on Website loaded in Gecko within a Visual Basic application [VS2015]如何在 Visual Basic 应用程序中单击 Gecko 中加载的网站 [VS2015]
【发布时间】:2016-06-04 04:39:08
【问题描述】:

在用 Visual Basic (VS2015) 编写的 HAM RADIO 应用程序中,我使用 VB 形式的 Gecko Web 浏览器。

在我使用 VB 程序 (URL = http://websdr.ewi.utwente.nl:8901/) 加载到 Gecko 浏览器的网站上,我想从我的 VB 应用程序中单击“CW-narrow”旋钮上的 [按软件代码]。此旋钮可缩小此基于 Web 的 SDR(软件定义无线电)中的接收过滤器

此旋钮是网站上表格的一部分。在 CW-Narrow 旋钮上用鼠标右键单击后,我在 FireBug 上看到了这一点(下面的 HTML 代码)。

“CW-Narrow”旋钮在表格中,我无法从我的 VB 应用程序中单击该旋钮。

谁能帮忙?

注意: 我在同一站点上需要的另一个控件,即静音复选框,正在使用以下 VB 代码:

  • GWB_SDR1_MyCall 是 VB 表单上的 Gecko 浏览器。

Dim MuteCheck As Gecko.DOM.GeckoInputElement = DirectCast(GWB_SDR1_MyCall.Document.GetElementById("mutecheckbox"), Gecko.DOM.GeckoInputElement) MuteCheck.Click()

运行此代码确实会使 SDR 上的音频静音。

希望有人可以帮助我点击桌子上的 CW-Narrow 旋钮。 (请参阅下面的网站复制粘贴)

<table>
<tbody>
<tr>
<tr>
<td>
<td>
<input type="button" onclick="setmf('cw',-0.78, -0.72);" value="CW-narrow">
</td>
<td>
<td>
<td>
<td>
</tr>
</tbody>
</table>

非常感谢!

奥诺德梅耶

【问题讨论】:

    标签: xpath visual-studio-2015 gecko


    【解决方案1】:

    试试

    GWB_SDR1_MyCall.Document.QuerySelector("div.ctl:nth-child(32) > table:nth-child(6) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > input:nth-child(1)").Click()
    

    我不熟悉您尝试使用的 Gecko API,因此很难判断您需要声明或强制转换为哪种类型。作为快捷方式,您可能想尝试使用后期绑定,例如

    Dim CWN As Object = GWB_SDR1_MyCall.Document.QuerySelector("div.ctl:nth-child(32) > table:nth-child(6) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > input:nth-child(1)")
    
    CWN.Click()
    

    您可能需要使用Option Strict Off 进行编译。

    如果您仍然遇到问题,请尝试使用Dim CWN = GWB_SDR1_MyCall.Document.QuerySelector("div.ctl:nth-child(32) &gt; table:nth-child(6) &gt; tbody:nth-child(1) &gt; tr:nth-child(2) &gt; td:nth-child(2) &gt; input:nth-child(1)"),然后在该指令之后中断调试器并检查运行时类型。

    【讨论】:

    • 抛出异常:SDR_Monitor.exe 中的“System.InvalidCastException”
    • 尝试 Dim CWN As Gecko.Element CWN = W.DocumentElement.QuerySelector("div.ctl:nth-child(32) > table:nth-child(6) > tbody:nth-child( 1) > tr:nth-child(2) > td:nth-child(2) > input:nth-child(1)") Debug.Print(CWN.ToString) Catch ex As Exception Debug.Print("Error in CW_Narrow SUB") 结束尝试
    • @Onno,我已经用一些可能有帮助的建议编辑了答案。
    • 解决方案:Dim CWN As Gecko.DOM.GeckoInputElement = GeckoWeb.Document.Body.QuerySelector("div.ctl:nth-child(32) > table:nth-child(6) > tbody: nth-child(1) > tr:nth-child(2) > td:nth-child(2) > input:nth-child(1)") CWN.Click() 现在正在工作!!!
    • 马丁一个问题:你是如何为查询选择器设置字符串的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-29
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 2012-11-12
    相关资源
    最近更新 更多