英文:
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 -->
<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>
<!-- end snippet -->
When not visible
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<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>
<!-- 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("a[href='#pro-content-pro']")
If P.Attribute("class")="disabled" Then
Else
P.Click
End If
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论