我正在使用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>
我试图使用
定位元素- 两个类的相对XPath:
.//*[@class='t-next-pd continue-to-query button-text']
,.//*[@class='right-align']
- 通过文字
- 通过部分文本
- 链接
- 由CSSSELECTOR
- 文本的相对XPath
- 由Absolute XPath(最后一个优先级)
- className
- 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>
继续停用
填写详细信息后等待一秒钟。Phantomjs立即搜索激活的继续按钮。这很可能是一个计时问题。继续按钮可能需要500毫秒至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')