0

Using Selenium to perform some webscraping. Have it log in to a site, where an HTML table of data is returned with five values at a time. I'm going to have Selenium scrape a particular bit of data off the table, write to a file, click next, and repeat with the next five.

New automation script. I've a myriad of variations of get_attribute, find_elements_by_class_name, etc. Example:

pnum = prtnames.get_attribute("title")
for x in prtnames:
    print('pnum')

Here's the HTML from one of the returned values:

<div class="text-container prtname"><span class="PrtName" title="P011">P011</span></div>

I need to get that "P011" value. Obviously Selenium doesn't have "find_elements_by_title", and there is no HTML id for the value. The Xpath for that line of HTML is:

//*[@id="printerConnectTable"]/tbody/tr[5]/td/table/tbody/tr[1]/td[2]/div/span

But I don't see a reference to "title" or "P011" in that Xpath.

    pnum = prtnames.get_attribute("title")
AttributeError: 'list' object has no attribute 'get_attribute'

It's like get_attribute doesn't exist, but there is some (albeit not much) documentation on it.

Fundamentally I'd like to grab that "P011" value and print to console, then I know Selenium is working with the right data.

P.S. I'm self-taught with all of this, I'm automating a sysadmin task.

1
  • do you want to get elements with a certain title, or do you want to get elements by a different attribute and verify that the title attribute is what you expect it is? Commented Jun 21, 2019 at 16:06

1 Answer 1

1

I think the problem is that prtnames is a list of element, not a specific element. You can use a list comprehension if you want a list of the attributes of titles for the list of prtnames.

pnums = [x.get_attribute('title') for x in prtnames]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.