【发布时间】:2018-12-06 14:11:36
【问题描述】:
我正在使用 PyCharm 和 Selenium 网络驱动程序测试包含多个字段的网络表单。
网页上有两个类似的DIV,分别是电话和电子邮件:
<div class="popup-subscribe-new__content">
<div class="field field_type_email js-field-custom-email js-field">
<input type="phone" name="phone" placeholder="Phone Number" autocomplete="off" required="required" class="field__input js-field-input js-inputmask-phone" pattern="^[0-9\+\-\( \)]+$" data-trim="true" pattern-flags="i">
<div class="field__error">Enter the phone number</div>
</div>
</div>
和
<div class="popup-subscribe-new__content">
<div class="field field_type_email js-field-custom-email js-field">
<input type="email" name="email" placeholder="E-mail" autocomplete="off" required="required" class="field__input js-field-input" pattern="^([A-Za-z0-9_\.\+\-])+@([A-Za-z0-9_\.\-])+\.([A-Za-z]{2,4})$" data-trim="true">
<div class="field__error">Enter the e-mail</div>
</div>
</div>
在我的测试中,我使用 phone_field = driver.find_element_by_name('phone') 进行电话搜索 和 email_field = driver.find_element_by_name('email') 用于电子邮件搜索
结果,测试成功找到了电话字段,但在尝试找到电子邮件字段后,PyCharp 回答为 ElementNotVisibleException: Message: element not visible
我哪里错了? 谢谢, 尤金
【问题讨论】:
-
检查
len(driver.find_elements_by_name('phone'))是否返回1或更多。如果更多-尝试不同的定位器 -
@Andersson 在我的情况下它返回 1
-
为什么将 phone_field 作为两个 Web 元素的变量名?
-
@Andersson 但 len_email = len(driver.find_elements_by_name('email')) 返回 5
-
@cruisepandey 哦,只是错字,已经解决了问题,有 email_field = driver.find_element_by_name('email')
标签: python html selenium testing pycharm