-2

I want to get the text "Cleaning General: Audit Based Update" in the HTML below. It should have the xpath:

//*[@id="context_bar"]/table/tbody/tr/td[5]/div

How do I convert the following Python ElementTree code to Selenium?

browser.find_element_by_xpath('//*[@id="context_bar"]/table/tbody/tr/td[5]/div/@title').text()

with the following HTML:

image

5
  • 1) We can't reproduce this because we don't have the HTML. Please post the URL. 2) What error/issue do you get? When you try debugging your XPATH by successively adding parts to it, where does it stop working? Commented Sep 12, 2019 at 0:17
  • hi, 1) Internal site 2) I Just want to print text. Commented Sep 12, 2019 at 0:35
  • 1) Ok but we can't reproduce it. 2) Doesn't matter. To debug the xpath, the only sane method I know is start with just '//*[@id="context_bar"]/table/tbody, check it works, then add xpath components one-at-a-time until you find where the problem is. Tell us where that is. If you don't debug it and describe the problem better, then we can't help you. Commented Sep 12, 2019 at 0:37
  • hi,this code can you convert to selenium title = html.etree.HTML(content).xpath('//*[@id="context_bar"]/table/tbody/tr/td[5]/div/@title')[0] Commented Sep 12, 2019 at 0:47
  • Oh, you're asking us to convert Python ElementTree code to Selenium. I don't know Selenium but it should be easy, see the Selenium doc. Commented Sep 12, 2019 at 0:56

1 Answer 1

2

The method you're calling is find_element_by_xpath so it will return an element. if you want to get an attribute of an element then you'll need to call elem.get_attribute(...)

div = browser.find_element_by_xpath('//*[@id="context_bar"]/table/tbody/tr/td[5]/div')
title = div.get_attribute('title')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.