How to check if a webelement has attribute in Python? or What's the best way to verify a webelement h

16 Replies, 655 Views

"What's the best way to verify a webelement has attribute using Python?"

Hey folks!

Stuck on how to check if a webelement has attribute in Python with Selenium? Like, I need to see if an element has a 'data-id' or 'class' attr before doing stuff with it.

Tried `get_attribute()`, but it returns `None` if the attr doesn't exist. Is there a cleaner way than checking for `None`? Or maybe a built-in method I’m missing?

Kinda new to this, so any tips or snippets would be awesome!

Thanks in advance!

(PS: Googled "webelement has attribute python" but didn’t find a straight answer.)

Messages In This Thread
How to check if a webelement has attribute in Python? or What's the best way to verify a webelement h - by - 13-05-2024, 01:53 AM



Users browsing this thread: 1 Guest(s)