0

Trying to get the color WHITE out of the line of code.

<a href="javascript:void(0)" class="itemAttr current" title="WHITE" data- 
value="WHITE"><img src="https://gloimg.rglcdn.com/rosegal/pdm-product- 
pic/Clothing/2019/06/05thumb-img/1559762268621192281.jpg"></a>

I've tried this:

color = driver.find_element_by_xpath("""//p[@id="select-attr- 
 0"]/a[@href="javascript:void(0)"]@title""").click()

I get this error message:

The string '//p[@id="select-attr-0"]/a[@href="javascript:void(0)"]@title' is not a valid XPath expression.

What I want is to get "WHITE".

Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45
Dave
  • 11
  • 3

3 Answers3

2

It looks like you are missing a / before the @title attribute. Try this xpath instead:

//p[@id="select-attr-0"]/a[@href="javascript:void(0)"]/@title
srk
  • 1,625
  • 1
  • 10
  • 26
1

In order to get an attribute value of an element, you need to put '/' before the '@title', so the following should work (provided the parent element p is correctly addressed):

//p[@id="select-attr-0"]/a[@href="javascript:void(0)"]/@title

When working with XPATHs, it is often useful to use one of free online testers to get instant path feedback, e.g. this one

0

Try using the below xpath snippet.

//p[@id='select-attr- 0']//child::a[@value='WHITE']

Zohair
  • 268
  • 2
  • 7