我正在使用phantomjs版本的1.1.0和phantomjs-2.1.1.exe作为windows。
这是HTML代码
<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>我尝试使用
.//*[@class='t-next-pd continue-to-query button-text']、.//*[@class='right-align']似乎什么都起不到作用。
只有当我输入姓名和年龄时,才会激活“继续”按钮。这是“继续”按钮未激活时的代码。
<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>发布于 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:-
# code
# to
# fill the form
time.sleep(2)
driver.find_element_by_css_selector('a.t-next-pd.continue-to-query.button-text')https://stackoverflow.com/questions/40765579
复制相似问题