1

The webpage have a code:

<table> <tbody> <tr> <td> <time data-timestamp="1458895194718" title="2016-03-25 11:39:54<small class="milliseconds">.718</small>">11:39</time> </td> <td> <span class="invisep"><</span> <mark class="nickname" style="cursor:pointer; color:#03DC03">usernickname</mark> <span class="invisep">></span> </td> 

I need to get style= and I received advice to use:

from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from selenium.webdriver.firefox.webdriver import FirefoxProfile colorelement = driver.find_element_by_css_selector('mark.nickname') color = colorelement.get_attribute('style') 

and it works but my code returns me only the first value found. The web page have many blocks and everyone has block The code find_elements_by_css_selector returns "AttributeError: 'list' object has no attribute 'get_attribute'" Could you help me please, how can I get second(third etc.) value or maybe it can be found all the values at once

1
  • The code you have uses find_element_* which only returns the first match even if there are more than one. It sounds like you want find_element**s**_* which will return all the elements that match. See Florent B.'s answer below.
    – JeffC
    CommentedMar 29, 2016 at 18:53

1 Answer 1

1

You need to call get_attribute for each element:

elements = driver.find_elements_by_css_selector('mark.nickname') for element in elements: print element.get_attribute('style') print color 

Or with a list comprehension :

elements = driver.find_elements_by_css_selector('mark.nickname') colors = [element.get_attribute('style') for element in elements] for color in colors: print color 

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.