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

16 Replies, 658 Views

Pro tip: If you’re using pytest or unittest, you could even make a custom assertion for this.

Something like:

```python
def assert_has_attribute(element, attr_name):
assert element.get_attribute(attr_name) is not None, f"Missing {attr_name}"
```

Makes your tests cleaner if you’re doing lots of checks. For webelement has attribute python, this is a neat way to keep things DRY.

Messages In This Thread



Users browsing this thread: 1 Guest(s)