Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d38f4a3

Browse files
author
Baiju Muthukadan
committed
Merge pull request baijum#14 from Sowrabha8/minor_fix
Modified the Selenium python doc.
2 parents fc88c41 + 6a1c503 commit d38f4a3

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

source/getting-started.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ in it::
6666
WebDriver offers a number of ways to find elements using one of the
6767
`find_element_by_*` methods. For example, the input text element can
6868
be located by its `name` attribute using `find_element_by_name`
69-
method. Detailed explanation of findind elements is available in the
69+
method. Detailed explanation of finding elements is available in the
7070
:ref:`locating-elements` chapter::
7171

7272
elem = driver.find_element_by_name("q")
@@ -223,8 +223,8 @@ site. You can confirm it by asserting "Google" in the title::
223223
The `tearDown` method will get called after every test method. This
224224
is a place to do all cleanup actions. In the current method, the
225225
browser window is closed. You can also call `quit` method instead of
226-
`close`. The `quit` will exit all entire browser where as `close`
227-
will close one tab, but if it just one tab, by default most browser
226+
`close`. The `quit` will exit entire browser, where as `close`
227+
will close a tab, but if it is just one tab, by default most browser
228228
will exit entirely.::
229229

230230
def tearDown(self):

source/navigating.rst

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ Filling in forms
7474

7575
We've already seen how to enter text into a textarea or text field,
7676
but what about the other elements? You can "toggle" the state of
77-
checkboxes, and you can use "setSelected" to set something like an
77+
drop down, and you can use "setSelected" to set something like an
7878
`OPTION` tag selected. Dealing with `SELECT` tags isn't too bad::
7979

80-
select = driver.find_element_by_xpath("//select")
81-
all_options = select.find_elements_by_tag_name("option")
80+
element = driver.find_element_by_xpath("//select[@name='name']")
81+
all_options = element.find_elements_by_tag_name("option")
8282
for option in all_options:
8383
print "Value is: %s" % option.get_attribute("value")
8484
option.click()
@@ -87,19 +87,31 @@ This will find the first "SELECT" element on the page, and cycle
8787
through each of it's OPTIONs in turn, printing out their values, and
8888
selecting each in turn.
8989

90-
.. As you can see, this isn't the most efficient
91-
.. way of dealing with SELECT elements . WebDriver's support classes
92-
.. include one called "Select", which provides useful methods for
93-
.. interacting with these.
90+
As you can see, this isn't the most efficient
91+
way of dealing with SELECT elements . WebDriver's support classes
92+
include one called "Select", which provides useful methods for
93+
interacting with these.
9494

95-
.. ::
95+
::
96+
97+
select = Select(driver.find_element_by_name('name'))
98+
select.select_by_index(index)
99+
select.select_by_visible_text("text")
100+
select.select_by_value(value)
101+
102+
103+
WebDriver also provides features for deselecting all the selected options::
96104

97-
.. select = driver.find_element_by_xpath("//select").select() #<- FIXME: API
98-
.. select.deselectAll() #<- FIXME: API
99-
.. select.selectByVisibleText("Edam") #<- FIXME: API
105+
select = Select(driver.find_element_by_id('id'))
106+
select.deselect_all()
100107

101-
.. This will deselect all OPTIONs from the first SELECT on the page, and
102-
.. then select the OPTION with the displayed text of "Edam".
108+
This will deselect all OPTIONs from the first SELECT on the page.
109+
110+
Suppose in a test, we need the list of all default selected options, Select
111+
class provides a method that returns a list::
112+
113+
select = Select(driver.find_element_by_xpath("xpath"))
114+
all_options = select.all_selected_options()
103115

104116
Once you've finished filling out the form, you probably want to submit
105117
it. One way to do this would be to find the "submit" button and click
@@ -165,6 +177,10 @@ and you can specify the frame by its index too. That is::
165177
would go to the frame named "child" of the first subframe of the frame
166178
called "frameName". **All frames are evaluated as if from *top*.**
167179

180+
Once we are done with working on frames, we will have to come back
181+
to the parent frame which can be done using::
182+
183+
driver.switch_to_default_content()
168184

169185
Popup dialogs
170186
~~~~~~~~~~~~~

0 commit comments

Comments
 (0)