Reputation: 25
Sample code:
<div class="loginbox">some code</div>
<div class="loginbox">other code</div>
<div class="loginbox">
<p> style="color: Red;">Test Extract</p>
</div>
Using Selenium Web Driver, I would like to extract the text Test Extract
within the paragraph element which is nested within a div, whose class name is shared with other div classes. c# preferred.
Upvotes: 1
Views: 3635
Reputation: 81
C# code to get the text from the locator specified,
IWebElement element = Browser.GetElementByCssSelector("div.loginbox p");
string text = element.Text;
Upvotes: 0
Reputation: 306
You can try below method:
driver.findElement(By.xpath("//div[@class='loginbox']/p")).getText();
EDITED
You should use =
inside the square braces like:
driver.findElement(By.xpath("//div[@class='loginbox']/p");
Upvotes: 3