【发布时间】:2014-01-02 08:56:46
【问题描述】:
<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>
I 以上代码我要查找请仅使用字母、数字、句点、单个空格和下划线消息。它的 xpath 是 /html/body/section[2]/div/div/form/article/div/div/span 但它没有被 gettext()访问> 方法。 请问如何访问????
【问题讨论】:
-
by xpath //span[@id='error_firstname'] by css #error_firstname by id error_firstname 最后是getText()
-
该元素可访问,但 getText() 未获取错误消息
-
检查 Driver.FindElement(By.id("error_firstname")).isDisplayed() 在使用 getText() 方法之前返回 true。因为它获取元素的可见(即不被 CSS 隐藏)innerText。
-
谢谢 Anuragh27crony 它的工作......
标签: selenium selenium-webdriver