我有这个HTML元素代码,目前正在努力找出它,以使用它来单击显示问题的选项卡。由于“问题”没有唯一的类名或元素ID,因此我无法确定如何发送Click()。
我已经尝试检查z-index是否可以用作索引(假定)并在代码行下面使用
browser.switch_to_frame(a[3])
但是似乎我错了。
HTML代码如下
<div class="TabsViewPort" style="position: relative; overflow: hidden; width: 896px; height: 22px; float: left;">
<div style="overflow: visible; float: left; width: 897px; top: 0px; left: 0px;">
<dl class="OuterOuterTab">
<dd class="OuterTab" artabid="955000038" arwindowid="0" style="top: 1px; z-index: 1; left: 0px; visibility: inherit; display: block;"><span class="TabLeftRounded"> </span>
<span class="Tab"><a href="javascript:" class="btn f1" style="color:#000000;">My Profile</a>
</span>
<span class="TabRight"> </span>
</dd>
<dd class="OuterTabSelected" artabid="600000203" arwindowid="0" style="top: 1px; z-index: 3; left: 63px; visibility: inherit; display: block;"><span class="TabLeft"> </span>
<span class="Tab"><a href="javascript:" class="btn f1">Approval</a>
</span>
<span class="TabRight"> </span>
</dd>
<dd class="OuterTab" artabid="536870915" arwindowid="0" style="top: 1px; z-index: 1; left: 409px; visibility: inherit; display: block;"><span class="TabLeft"> </span>
<span class="Tab"><a href="javascript:" class="btn f1">Problem</a>
</span>
<span class="TabRight"> </span>
</dd>
</dl>
</div>
</div>
文本为问题的元素是启用了JavaScript的元素,因此对于该元素上的click()
,您必须诱导WebDriverWait,以便使[元素可单击],并且可以使用以下任一解决方案:XPATH
A:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='TabsViewPort']//dl[@class='OuterOuterTab']//dd[@class='OuterTab']//a[@class='btn f1' and text()='Problem']"))).click()
XPATH
B(缩短):WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='btn f1' and text()='Problem']"))).click()
注
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
frame_to_be_available_and_switch_to_it
()