blob: 3be8a69b02785e1f07fe47061da1de7e54a4f66e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
def traverse():
//! [Traversing with QWebElement]
frame.setHtml("<html><body><p>First Paragraph</p><p>Second Paragraph</p></body></html>")
doc = frame.documentElement()
body = doc.firstChild()
firstParagraph = body.firstChild()
secondParagraph = firstParagraph.nextSibling()
//! [Traversing with QWebElement]
def findButtonAndClick():
frame.setHtml("<form name=\"myform\" action=\"submit_form.asp\" method=\"get\">" \
"<input type=\"text\" name=\"myfield\">" \
"<input type=\"submit\" value=\"Submit\">" \
"</form>")
//! [Calling a DOM element method]
document = frame.documentElement()
# Assume that the document has the following structure:
#
# <form name="myform" action="submit_form.asp" method="get">
# <input type="text" name="myfield">
# <input type="submit" value="Submit">
# </form>
button = document.findFirst("input[type=submit]")
button.evaluateJavaScript("click()")
//! [Calling a DOM element method]
def autocomplete1():
document = frame.documentElement()
//! [autocomplete1]
firstTextInput = document.findFirst("input[type=text]")
storedText = firstTextInput.attribute("value")
//! [autocomplete1]
def autocomplete2():
document = frame.documentElement()
storedText = "text"
//! [autocomplete2]
firstTextInput = document.findFirst("input[type=text]")
textInput.setAttribute("value", storedText)
//! [autocomplete2]
def findAll():
//! [FindAll]
document = frame.documentElement()
# Assume the document has the following structure:
#
# <p class=intro>
# <span>Intro</span>
# <span>Snippets</span>
# </p>
# <p>
# <span>Content</span>
# <span>Here</span>
# </p>
//! [FindAll intro]
allSpans = document.findAll("span")
introSpans = document.findAll("p.intro span")
//! [FindAll intro] //! [FindAll]
|