【发布时间】:2014-06-27 18:44:54
【问题描述】:
我有一些代码可以根据可见文本查找元素。
# Defines the text I am looking for
productName = "customer x job"
#Finds the element I am looking for
inputElement = driver.find_element_by_xpath(".//*[@id='demo_top']/div/table[2]/tbody/tr/td[1]/ul/li[2]/ul/li[1]/a".format(productName))
我需要单击右侧的一个框。
元素的具体xpath为:
#What I just found
/html/body/div[1]/div/div/table[2]/tbody/tr/td[1]/ul/li[2]/ul/li[1]/a
#The box I actually want to click
/html/body/div[1]/div/div/table[2]/tbody/tr/td[1]/ul/li[2]/ul/li[1]/span/a
所以我只需要将“/span/a”添加到 inputElement 的 xpath 中。问题是,我不知道这个元素的具体 xpath。有没有办法让我将 inputElement 转换为特定的 xpath,所以我可以将“/span/a”附加到它的末尾并单击该元素?
编辑:好像我弄错了,我需要将最后的“a”替换为“span/a”
下面是html:
<li class="TCbullet">
<span>
<a class="editCategory " onclick="return hs.htmlExpand(this, { objectType: 'iframe' } );" href="cat-frame-category.php?categoryID=1340"> </a> #I want to click this
<span class="sort">sort: 0</span>
</span>
<a class="anchorCategory" alt="Eden Cognitive Content" href="?ownerID=C518&g=1085&t=1340">Eden Cognitive Content</a> # I have found this
</li>
我想访问editCategory 链接,我找到了anchorCategory 链接。
【问题讨论】:
标签: python selenium xpath webdriver children