質問

I have the following HTML code:

div id="flashMessage" class="error"> 
<span>Saved Section.</span>
<div id="errors" class="clearfix">
</div>

I would like to get the text which is contained in span, I tried all the locators.

Could someone please help me with the respective command and css or xpath locator in selenium, for the above query?

役に立ちましたか?

解決

This should work for you:

string spanText = driver.findElement(By.cssSelector("div#flashMessage>span")).getText();

I'm not sure why the same locator wouldn't work for success messages, but you can try this:

string spanText = driver.findElement(By.cssSelector("div#flashMessage.msg>span")).getText();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top