点击”Webpage”选项卡,如果可见。

huangapple go评论78阅读模式
英文:

Click on Webpage tab if it is visible

问题

以下是已翻译的代码部分:

Set P = D.FindElementByCss("a[href='#pro-content-pro']")
P.Click

请注意,这是您提供的代码的翻译。如果要根据可见性条件来执行不同的操作,请考虑添加条件语句来检查标签是否可见,然后相应地执行点击操作或跳过。这将取决于您使用的编程语言和框架。

英文:

I have been trying to click on tab in a webpage using the code

Set P = D.FindElementByCss("a[href='#pro-content-pro']")
    P.Click

which works fine with the above code if the tab is visible in the webpage, if it is not visible then that is not going to work.. Below are the HTML codes

When Visible

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;li data-bind=&quot;attr:{ &#39;id&#39;: id }, click: onClick, visible: isVisible, css: {&#39;active&#39;: isActive, &#39;disabled-control&#39;: !isEnabled() }&quot; class=&quot;active&quot;&gt;
                &lt;a data-toggle=&quot;tab&quot; role=&quot;tab&quot; data-bind=&quot;attr:{ href: &#39;#&#39; + sectionId, id: linkId }, css: { &#39;disabled&#39;: !isEnabled() }&quot; href=&quot;#pro-content-pro&quot;&gt;
                    &lt;span data-bind=&quot;text: title&quot;&gt;Proforma&lt;/span&gt;
                &lt;/a&gt;
            &lt;/li&gt;

<!-- end snippet -->

When not visible

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;li data-bind=&quot;attr:{ &#39;id&#39;: id }, click: onClick, visible: isVisible, css: {&#39;active&#39;: isActive, &#39;disabled-control&#39;: !isEnabled() }&quot; class=&quot;disabled-control&quot;&gt;
                &lt;a data-toggle=&quot;tab&quot; role=&quot;tab&quot; data-bind=&quot;attr:{ href: &#39;#&#39; + sectionId, id: linkId }, css: { &#39;disabled&#39;: !isEnabled() }&quot; href=&quot;#pro-content-pro&quot; class=&quot;disabled&quot;&gt;
                    &lt;span data-bind=&quot;text: title&quot;&gt;Proforma&lt;/span&gt;
                &lt;/a&gt;
            &lt;/li&gt;

<!-- end snippet -->

Suggest me the correct code if the tab is not visible then skip else click on the tab if it is visible.

Thanks a lot.

答案1

得分: 2

如果您使用Selenium,请尝试以下代码:

Set P = D.FindElementByCss("a[href='#pro-content-pro']")
If P.Attribute("class") = "disabled" Then
Else    
    P.Click
End If
英文:

If you use Selenium then try this

Set P = D.FindElementByCss(&quot;a[href=&#39;#pro-content-pro&#39;]&quot;)
    If P.Attribute(&quot;class&quot;)=&quot;disabled&quot; Then
    Else    
        P.Click
    End If

huangapple
  • 本文由 发表于 2023年7月20日 16:08:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76727856.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定