0

ProductNames is an array of required data when using this line:

ProductNames[3].find_element_by_css_selector('.aok-align-bottom').get_attribute("innerHTML")

I'm getting this:

<span class="a-icon-alt">4.3 out of 5 stars</span>

So how can I extract only exactly text 4.3 out of 5 stars from span tag

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
div47
  • 22
  • 1

3 Answers3

0

You should include in your css_selector this >span too, and search get_attribute("innetHTML") on <span class="a-icon-alt">4.3 out of 5 stars</span>

Norayr Sargsyan
  • 1,737
  • 1
  • 12
  • 26
0

Try something like this:

ProductNames[3].find_element_by_css_selector('.aok-align-bottom').get_attribute("innerHTML").text
Haris
  • 68
  • 9
  • this one tried but after using get_attribute it becomes string so,string has no attribute text – div47 Jul 08 '20 at 06:29
0

You don't extract from innerHTML. Rather you extract text or the value of any attribute of a WebElement.

To extract the text _4.3 out of 5 stars_ you need to move one step deeper to the <span> and you can use the following Locator Strategy:

ProductNames[3].find_element_by_css_selector('.aok-align-bottom>span.a-icon-alt').get_attribute("innerHTML")

Or simply:

ProductNames[3].find_element_by_css_selector('.aok-align-bottom>span').get_attribute("innerHTML")

As an alternative, you can also use the text attribute as follows:

ProductNames[3].find_element_by_css_selector('.aok-align-bottom>span.a-icon-alt').text

Or simply:

ProductNames[3].find_element_by_css_selector('.aok-align-bottom>span').text

References

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352