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

16 Replies, 649 Views

Hey! Yeah, `get_attribute()` is the way to go, but checking for `None` is kinda the standard approach.

If you want something cleaner, you could wrap it in a helper function like:

```python
def has_attribute(element, attr_name):
return element.get_attribute(attr_name) is not None
```

Not built-in, but saves you from repeating the `None` check everywhere.

For webelement has attribute python, this is pretty much the simplest solution unless you dig into JS execution, which is overkill.

Messages In This Thread



Users browsing this thread: 1 Guest(s)