首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >请说明如何在span标签中访问消息。

请说明如何在span标签中访问消息。
EN

Stack Overflow用户
提问于 2014-01-02 08:56:46
回答 2查看 261关注 0票数 1
代码语言:javascript
复制
<html>
<body>
<section id="click" class="content mCustomScrollbar _mCS_1">
<div id="mCSB_1" class="mCustomScrollBox mCS-dark" style="position:relative; height:100%; overflow:hidden; max-width:100%;">
<div class="mCSB_container" style="position:relative; top:0;">
<form id="registration" action="http://abcd.com/setup/user-registration/index" method="post" name="registration">
<article class="frm-content">
<div class="leftsection">
<div class="form-element">
<fieldset>
<label>
<input id="firstname" type="text" maxlength="50" value="" name="firstname" style="border: 1px solid red;">
    <label>
<span class="required">*</span>
First Name:
</label>
<input id="firstname" type="text" maxlength="50" value="" name="firstname"     style="border: 1px solid red;">
<span id="error_firstname" class="errormsg" role="alert">Please use only letters,numbers, period, single space and underscore</span>
</fieldset>
</article>
</div>
</section>
</body>
</html>

以上代码我想找到请只使用字母,数字,句号,空格和下划线消息。它的xpath是/html/body/section2/div/div/form/article/div/div/span,但它不是通过gettext()方法访问的。Pls如何访问?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-01-02 11:29:59

getText()方法只获取相关元素的可见(即不被CSS隐藏) innerText。这可能是问题的原因之一。

请尝试以下检查是否显示元素。

代码语言:javascript
复制
Driver.FindElement(By.id("error_firstname")).isDisplayed();

您可以添加WebDriverwait,直到显示该元素,然后从该元素中获取文本。

代码语言:javascript
复制
WebDriverWait Driver_Wait=new WebDriverWait(Driver, 10); //10 denotes Total_Secs to wait
Driver_Wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("error_firstname")));

希望这能有所帮助。

票数 1
EN

Stack Overflow用户

发布于 2014-01-02 12:33:34

通过使用id "error_firstname“,我们只能得到span中以id作为error_firstname的值。

所以使用id "click“,这是最好的服务。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20879366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档