python - Webdriver. How to retrieve the xpath of found element? -
i have bit of code finds element based on visible text.
# defines text looking productname = "customer x job" #finds element looking 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))
i need click box right of this.
the specific xpath of element is:
#what found /html/body/div[1]/div/div/table[2]/tbody/tr/td[1]/ul/li[2]/ul/li[1]/a #the box want click /html/body/div[1]/div/div/table[2]/tbody/tr/td[1]/ul/li[2]/ul/li[1]/span/a
so need add "/span/a" xpath of inputelement. issue is, don't know specific xpath of element. there way me convert inputelement specific xpath, can append "/span/a" end of , click element?
edit: seems mistaken, need replace final "a" "span/a"
below 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 click <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> # have found </li>
i want access editcatagory link, , have found anchorcategory link.
you can call find_element_by_xpath()
on element have found:
link = inputelement.find_element_by_xpath('./preceding-sibling::span/a')
this select a
tag inside span
following a
tag have found.
Comments
Post a Comment