Erhan Yumer
Erhan Yumer

Reputation: 53

Selenium WebDriver get text inside of a span

I'm trying to extract the "This is our address" text inside of a span where HTML code are as follows:

<div id="comp-kvi6khho" class="2hij5_3bcaz">
<p class="font_8">
<span style="letter-spacing:normal;">
<span class="color_11">This is our address</span>

I have tried:

driver.findElement(By.className("color_11")).getText();
driver.findElement(By.cssSelector("#comp-kvi6khho > p:nth-child(1) > span:nth-child(1) > span:nth-child(1)")).getText();
driver.findElement(By.xpath("/html/body/div[1]/div/div[3]/div/main/div/div/div/div[2]/div/div/div/section[9]/div[2]/div[1]/div[2]/div/div[4]/p/span/span")).getAttribute("InnerHTML");

so far. But all of them I get Unable to locate element error. How can I extract the text inside of most inner span class?

Upvotes: 0

Views: 478

Answers (1)

Erhan Yumer
Erhan Yumer

Reputation: 53

Ok so I was not aware of the existence of iframes. The element I was looking for is inside of an iframe. First, I had to locate the iframe, then switch to it and then I located the element itself.

The code I used for that is below:

driver.switchTo().frame("iframe").findElement(By.cssSelector("#comp-kvi6khho > p:nth-child(1) > span:nth-child(1) > span:nth-child(1)")).getText();

Upvotes: 1

Related Questions