0

I want to check out if any html tags have <style> attribute like <a style = ..> or <h1 style = ...> or <div style = ..> etc. I used below code but it could not be run:

driver = webdriver.Chrome(web_driver_address, options=op)
driver.get(url)

elems = driver.find_elements_by_xpath("[@style]")

How can i fix this?

2 Answers 2

1

Your XPath is missing element tag name.
In your case it can be any tag name, but it still should be there as a part of syntax, so you should use * like any there.
Also, you are missing the // that means the element can be anywhere on the page.
So the correct XPath expression will be something like this:

elems = driver.find_elements_by_xpath("//*[@style]")

Don't forget to add some wait / delay to let page load all the elements before you get them

Sign up to request clarification or add additional context in comments.

Comments

1

xpath needs tag to be valid. If you don't want a specific tag use *

find_elements_by_xpath("//*[@style]")

Or with css_selector

find_elements_by_css_selector("[style]")

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.