我将直截了当地追逐和追问:
首先,这是我的代码(非常简单):
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select, WebDriverWait
el = driver.find_element_by_id("id1")
el.clear()
el.send_keys("2147000001")
el = driver.find_element_by_id("id2")
el.click()
el = driver.find_element_by_id("id3")
el.click()
textbox = driver.find_element_by_id("id4")
asd = textbox.get_attribute("innerHTML")
print asd
我面临的问题是它什么都不打印。我用firebug检查了id4元素,它是这样的:
<textarea spellcheck="false" class="debug hint" id="id4" style="display: inline;">
<?xml version="1.0"?>
<?xml version="1.0"?>
org.oneandone.ipayment.fraud.wrappers.SimilarIpaymentIdsResponse {
*ipaymentIds => org.oneandone.ipayment.fraud.IpaymentIds {
ipaymentId => [
0 => 80000000000
1 => 2147000165
2 => 2147000180
3 => 2147000130
4 => 2147000190
5 => 2147000192
6 => 2147000197
7 => 2147000144
8 => 2147000151
9 => 2147000198
10 => 2147000001
11 => 2147000170
12 => 2147000185
13 => 2147000179
14 => 2147000182
15 => 2147000183
16 => 2147000186
17 => 2147000193
18 => 2147000199
19 => 2147000201
20 => 2147000202
21 => 2147000204
22 => 2147000187
23 => 2147000218
24 => 2147000222
25 => 2147000301
26 => 2147000433
27 => 2147000434
28 => 2147000438
29 => 2147000461
30 => 2147000120
31 => 2147000462
32 => 2147002088
33 => 2147002672
34 => 2147003278
35 => 2147000229
36 => 2147000232
37 => 2147000326
]
__id => "0.97800600 1383227941"
}
errorcode => 0
additional => "Similar ipaymentIds of 2147000001 retrieved."
__id => "
0.97788900 1383227941"
}</textarea>
如果我尝试使用outerHTML,它会打印除XML之外的所有内容。这是为什么?我怎样才能获得我需要的信息?它是通过javascript生成的。
答案 0 :(得分:0)
我已经设法自己找到了这个问题的答案(最后);在实际打印出值之前,脚本需要超时“time.sleep(1)”,因为该字段是使用jquery填充的。 没有超时,脚本实际上会在填充元素之前获取元素的innerHTML。这就是输出为空的原因。