<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如何访问?
发布于 2014-01-02 11:29:59
getText()方法只获取相关元素的可见(即不被CSS隐藏) innerText。这可能是问题的原因之一。
请尝试以下检查是否显示元素。
Driver.FindElement(By.id("error_firstname")).isDisplayed();您可以添加WebDriverwait,直到显示该元素,然后从该元素中获取文本。
WebDriverWait Driver_Wait=new WebDriverWait(Driver, 10); //10 denotes Total_Secs to wait
Driver_Wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("error_firstname")));希望这能有所帮助。
发布于 2014-01-02 12:33:34
通过使用id "error_firstname“,我们只能得到span中以id作为error_firstname的值。
所以使用id "click“,这是最好的服务。
https://stackoverflow.com/questions/20879366
复制相似问题