search

Home  >  Q&A  >  body text

Click on the web page tab (if visible)

I have been trying to use code to click a tab in a web page

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

The above code works fine if the tab is visible in the web page, but does not work if the tab is not visible. The following is the HTML code

When visible

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

When invisible

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

If the tab is not visible please suggest me the correct code and skip it otherwise click on the tab if the tab is visible.

Thank you so much.

P粉704066087P粉704066087485 days ago531

reply all(1)I'll reply

  • P粉464113078

    P粉4641130782023-09-14 18:03:20

    If you use Selenium, then try this

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

    reply
    0
  • Cancelreply