首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >元素未在幻影中找到,但在铬上工作很好。

元素未在幻影中找到,但在铬上工作很好。
EN

Stack Overflow用户
提问于 2016-11-23 13:16:40
回答 1查看 750关注 0票数 1

我正在使用phantomjs版本的1.1.0phantomjs-2.1.1.exe作为windows

继续激活

这是HTML代码

代码语言:javascript
复制
<div class="right-align" style="display: inline-block; vertical-align: middle; border-radius: 6px; margin-left: 20px; flex-grow: 100;">
<div>
<a class="t-next-pd continue-to-query button-text" style="background-color: rgb(11, 197, 216); color: rgb(255, 255, 255); height: 40px; padding: 0px 16px; text-decoration: none; display: inline-flex; font-weight: 500; font-size: 16px; border-radius: 4px; z-index: 100; cursor: pointer; align-items: center; justify-content: center; border: 1px solid rgb(11, 197, 216); width: 100%;">
<span style="display: inline-block;">CONTINUE</span>
</a>
</div>
</div>

我尝试使用

  1. 这两个类的相对xpath:.//*[@class='t-next-pd continue-to-query button-text'].//*[@class='right-align']
  2. 按文本
  3. 部分文本
  4. 通过链接
  5. 由cssSelector
  6. 相对xpath与文本
  7. 绝对xpath (最后优先级)
  8. 由ClassName
  9. javascript执行器
  10. 隐式等待和显式等待

似乎什么都起不到作用。

只有当我输入姓名和年龄时,才会激活“继续”按钮。这是“继续”按钮未激活时的代码。

代码语言:javascript
复制
<div class="right-align" style="display: inline-block; vertical-align: middle; border-radius: 6px; margin-left: 20px; flex-grow: 100;">
<div>
<a class="button-text" disabled="" style="background-color: rgb(199, 199, 199); color: rgb(255, 255, 255); height: 40px; padding: 0px 16px; display: inline-flex; text-decoration: none; font-weight: 500; font-size: 16px; border-radius: 4px; z-index: 100; cursor: pointer; align-items: center; justify-content: center; width: 100%;">
<span style="display: inline-block;">CONTINUE</span>
</a>
</div>
</div>

继续停用

EN

回答 1

Stack Overflow用户

发布于 2016-11-24 10:23:17

填写详细信息后,请稍等片刻。PhantomJS立即搜索已激活的“继续”按钮。这很可能是时间问题。“继续”按钮可能需要500 to至1秒才能激活。

因此,当PhantomJS开始搜索已激活的按钮时,它将找不到它,因为DOM中还不存在。

如果您使用的是Python,请使用time.sleep(2)。它停了2秒。这使DOM有时间将已激活的代码更改为激活的代码。

我用这个a.t-next-pd.continue-to-query.button-text找到激活的按钮。这是一个CSS选择器,它在我的测试用例中运行得很好:)

把它转换成你正在使用的语言。我在用Python:-

代码语言:javascript
复制
# code
# to
# fill the form
time.sleep(2)
driver.find_element_by_css_selector('a.t-next-pd.continue-to-query.button-text')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40765579

复制
相关文章

相似问题

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