Home > Software design >  Find span with 2 attributes Selenium
Find span with 2 attributes Selenium

Time:02-07

Just trying to code a web scraper with selenium which searchs for a span in a div which has an other span with a title in it.

<div ><div ><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAD4SURBVHgB3ZXNEYIwEIVfGA/iiRLszBawArACpQOtDDrAEwkX1iyQ8WY2BDj4zfAzzNtskn1sgI1R7qXXfUFEuf2SeaMIb3t/Hk/HqyiBMeZug3IEQqBbmqalV2g60xptSGt9hgDWsb43fSvRg8V8IQBpzAHLacTKJSuQkmBjRFsUY2HvCtjC1o6laHCGdQq5dVr5HeRHDWIt7K/BPHP7QzUQ4HR2SzNZgkimBFNhIN2G4ASkqOKngqrnetRYiTEBN6yBhsqtZFdi 9RORf7vBIEWdjql1BjnbXZsYWvfYrYwpNBArzGRRNx13SNBcpF2U56U6Kxegw CobhgOuqV7gAAAABJRU5ErkJggg==" alt="copy"><span  title="Total Volume (ALL Time, ALL Marketplaces)">Total Volume (ALL Time, ALL Marketplaces)</span><span  title="5325.23 ◎">5325.23 ◎</span></div></div>

The problem is that there are multiple divs with this class. So I have to find only this div which has the span with the title=Total Volume (ALL Time, ALL Marketplaces) in it and then print the span with the class=text-white fs-14px text-truncate attribute-value

Can anyone help me with this problem? So I only can scrap the right span in the div?

Thank you very much <3

CodePudding user response:

I think this would be helpful : WebElement el=driver.findElement(By.xpath("//div//span[contains(text(),'Total Volume')]//following-sibling::span")); System.out.println(el.getText());

CodePudding user response:

You can locate the span with class=text-white fs-14px text-truncate attribute-value by several ways. I would prefer this XPath:

//div[contains(@class,'attributes-column') and .//span[@title='Total Volume (ALL Time, ALL Marketplaces)']]//span[contains(@class,'attribute-value')]
  •  Tags:  
  • Related