Skip to content Skip to sidebar Skip to footer

How To Get An 'nth-of-type' In Selenium

I'm using Selenium Webdriver to check the text of this particular paragraph (the one highlighted in blue here): But how do I 'query' that paragraph? This is what I'm trying (not w

Solution 1:

findElement() is not a Python. Try below instead:

intro_text = hed_dek_wrapper.find_element_by_css_selector('p:nth-of-type(2)')
assert'Over the past 20 years, we have seen an evolution.' in intro_text.text

Solution 2:

just use this css selector for doing this :

#visual-7.hed-dek-wrapper >p:nth-of-type(2)  

and find element using css selector and it will give you the second p tag.

driver.find_element_by_css_selector("#visual-7.hed-dek-wrapper >p:nth-of-type(2)");

Post a Comment for "How To Get An 'nth-of-type' In Selenium"