-2

I have no clue why this is happening. I'm trying to convert what the webdriver returned (a money value of $1.00) to an integer so I can run it through a called function, but I can't split to take away the $ because of this error. Here is my code:

    element = driver.find_elements_by_css_selector(".something")[0]
    element2 = element.find_elements_by_tag_name('tag')[19]
    [s.split('$')[0:] for s in element2]
    element3 = int(element2)
    print(elment3.text)

I'm getting this reject

    TypeError: 'WebElement' object is not iterable

Shouldn't this be a list and be iterable?

Thanks!

code_newb
  • 1
  • 2

3 Answers3

1
TypeError: 'WebElement' object is not iterable

WebElement or WebDriver both are non-iterable. when you do find_elements it returns a list of web element that you can iterate.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0

element.find_elements_by_tag_name('tag') is probably indeed a list, but you are grabbing the element at index 19 -- so element2 is just a webelement. I don't know what you are trying to do, but that's why your code isn't working.

C. Peck
  • 3,641
  • 3
  • 19
  • 36
  • I see, since I'm telling it to just grab one thing it's telling me it's treating as a list and instead just a single webelement. It's a dollar value that I need to manipulate into a function. Do you have any idea how I can make that happen? – code_newb Jun 05 '21 at 13:52
  • *It's a dollar value that I need to manipulate into a function.* Exactly where is this dollar value in your code? Also I don’t know what it means to “manipulate into a function”….. do you mean pass it in as an argument? – C. Peck Jun 05 '21 at 17:08
  • That's correct, it will be an argument. The dollar value will be returned by the 'tag'. – code_newb Jun 06 '21 at 01:03
0

Okay, I figured it out! It was:

element3 = element2.text.strip('$')
code_newb
  • 1
  • 2