0

I'm tring to get the color and the image of this code:

 <a href="javascript:void(0)" class="logsss_event_cl itemAttr current " title="MULTI" data- 
 value="MULTI" data-logsss-const-value="{'x': 'change_color'}"><img 
 src="https://gloimg.rglcdn.com/rosegal/pdm-product-pic/Clothing/2020/12/24thumb- 
 img/1608776712993433956.jpg?im_scale=h34_1x"></a>

 <a href="javascript:void(0)" class="logsss_event_cl itemAttr  " title="LIGHT PINK" data-value="LIGHT 
 PINK" data-logsss-const-value="{'x': 'change_color'}"><img 
 src="https://gloimg.rglcdn.com/rosegal/pdm-product-pic/Clothing/2021/04/08thumb- 
 img/1617901013166741553.jpg?im_scale=h34_1x"></a>

Both of these look the same except in the class one ends in current.

My problem is I do not know how to get just the value of an element.

I've tried:

 color1a= driver.find_element_by_xpath('//*[@id="select-attr-0"]/a[1]').text

 color1a= driver.find_element_by_xpath("//*[@class='logsss_event_cl itemAttr 
 current']").get_Attribute("data-value").text

 tumb1= driver.find_element_by_xpath('//*[@id="select-attr-0"]/a[2]/img').text
vitaliis
  • 4,082
  • 5
  • 18
  • 40
dave
  • 23
  • 4

1 Answers1

1

To get the link use (first element):

link = driver.find_element_by_css_selector(".logsss_event_cl.itemAttr.current>img").get_attribute("src")

Second link:

link2 = driver.find_element_by_css_selector(".logsss_event_cl.itemAttr:nth-of-type(2)>img").get_attribute("src")

To get the color attribute of the second element:

color = driver.find_element_by_css_selector(".logsss_event_cl.itemAttr:nth-of-type(2)").get_attribute("data-value")

. is for class names. > - direct child. It is easier than xpath. You do not need to use .text.

If you want to use xpath: //*[@class='logsss_event_cl itemAttr current ']/img would be sufficient. If the color of the first element is MULTI, than you need attribute named value, not data-value.

vitaliis
  • 4,082
  • 5
  • 18
  • 40