Skip to content

Commit ea26ad2

Browse files
authored
Merge pull request #257 from seleniumbase/simplify-submit-method
Add submit() method to simplify driver.find_element_by_*().submit()
2 parents 78b4579 + 01a522b commit ea26ad2

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[<img src="https://cdn2.hubspot.net/hubfs/100006/images/super_logo_2h2.png" title="SeleniumBase" height="48">](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md)
22

3-
[<img src="https://img.shields.io/github/release/seleniumbase/SeleniumBase.svg" />](https://github.com/seleniumbase/SeleniumBase/releases) [<img src="https://travis-ci.org/seleniumbase/SeleniumBase.svg?branch=master" alt="Build Status" />](https://travis-ci.org/seleniumbase/SeleniumBase) [<img src="https://badges.gitter.im/seleniumbase/SeleniumBase.svg" alt="Join the Gitter Chat" />](https://gitter.im/seleniumbase/SeleniumBase)<br />
3+
[<img src="https://img.shields.io/github/release/seleniumbase/SeleniumBase.svg" />](https://github.com/seleniumbase/SeleniumBase/releases) [<img src="https://travis-ci.org/seleniumbase/SeleniumBase.svg?branch=master" alt="Build Status" />](https://travis-ci.org/seleniumbase/SeleniumBase) [<img src="https://badges.gitter.im/seleniumbase/SeleniumBase.svg" alt="Join the Gitter Chat" />](https://gitter.im/seleniumbase/SeleniumBase) [<img src="https://img.shields.io/github/stars/seleniumbase/seleniumbase.svg" alt="GitHub Stars" />](https://github.com/seleniumbase/SeleniumBase/stargazers)<br />
44

5-
A fast, simple, and reliable framework for automating UI testing and [prototyping JS tours](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/tour_examples/ReadMe.md). SeleniumBase uses [Pytest](https://docs.pytest.org/en/latest/) for running Python scripts, and [WebDriver](https://www.seleniumhq.org/) for controlling web browsers. [<img src="https://img.shields.io/github/stars/seleniumbase/seleniumbase.svg" alt="GitHub Stars" />](https://github.com/seleniumbase/SeleniumBase/stargazers)
5+
A fast, simple, and reliable framework for automating UI testing and [prototyping JS tours](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/tour_examples/ReadMe.md). SeleniumBase uses [Pytest](https://docs.pytest.org/en/latest/) and [WebDriver](https://www.seleniumhq.org/) for running Python scripts to control web browsers.
66

77
## <img src="https://cdn2.hubspot.net/hubfs/100006/images/sb_logo_box2.png" title="SeleniumBase" height="32"> Quick Start
88

help_docs/method_summary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ self.js_click(selector, by=By.CSS_SELECTOR)
144144

145145
self.jquery_click(selector, by=By.CSS_SELECTOR)
146146

147+
self.submit(selector, by=By.CSS_SELECTOR)
148+
147149
self.hide_element(selector, by=By.CSS_SELECTOR)
148150

149151
self.hide_elements(selector, by=By.CSS_SELECTOR)

seleniumbase/fixtures/base_case.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,15 @@ def jquery_click(self, selector, by=By.CSS_SELECTOR):
14251425
self.safe_execute_script(click_script)
14261426
self.__demo_mode_pause_if_active()
14271427

1428+
def submit(self, selector, by=By.CSS_SELECTOR):
1429+
""" Alternative to self.driver.find_element_by_*(SELECTOR).submit() """
1430+
if page_utils.is_xpath_selector(selector):
1431+
by = By.XPATH
1432+
element = self.wait_for_element_visible(
1433+
selector, by=by, timeout=settings.SMALL_TIMEOUT)
1434+
element.submit()
1435+
self.__demo_mode_pause_if_active()
1436+
14281437
def hide_element(self, selector, by=By.CSS_SELECTOR):
14291438
""" Hide the first element on the page that matches the selector. """
14301439
selector, by = self.__recalculate_selector(selector, by)

seleniumbase/utilities/selenium_ide/convert_ide.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,19 @@ def main():
158158
seleniumbase_lines.append(command)
159159
continue
160160

161+
# Handle .find_element_by_id() + .submit()
162+
data = re.match(
163+
r'''^(\s*)driver\.find_element_by_id\(\"(\S+)\"\)'''
164+
r'''\.submit\(\)\s*$''', line)
165+
if data:
166+
whitespace = data.group(1)
167+
selector = '#%s' % data.group(2).replace('#', '\\#')
168+
selector = selector.replace('[', '\\[').replace(']', '\\]')
169+
selector = selector.replace('.', '\\.')
170+
command = '''%sself.submit('%s')''' % (whitespace, selector)
171+
seleniumbase_lines.append(command)
172+
continue
173+
161174
# Handle .find_element_by_id() + .send_keys()
162175
data = re.match(
163176
r'''^(\s*)driver\.find_element_by_id\(\"(\S+)\"\)'''
@@ -200,6 +213,17 @@ def main():
200213
seleniumbase_lines.append(command)
201214
continue
202215

216+
# Handle .find_element_by_name() + .submit()
217+
data = re.match(
218+
r'''^(\s*)driver\.find_element_by_name\(\"(\S+)\"\)'''
219+
r'''\.submit\(\)\s*$''', line)
220+
if data:
221+
whitespace = data.group(1)
222+
selector = '[name="%s"]' % data.group(2)
223+
command = '''%sself.submit('%s')''' % (whitespace, selector)
224+
seleniumbase_lines.append(command)
225+
continue
226+
203227
# Handle .find_element_by_name() + .send_keys()
204228
data = re.match(
205229
r'''^(\s*)driver\.find_element_by_name\(\"(\S+)\"\)'''
@@ -240,6 +264,19 @@ def main():
240264
seleniumbase_lines.append(command)
241265
continue
242266

267+
# Handle .find_element_by_css_selector() + .submit()
268+
data = re.match(
269+
r'''^(\s*)driver\.find_element_by_css_selector\(\"([\S\s]+)\"\)'''
270+
r'''\.submit\(\)\s*$''', line)
271+
if data:
272+
whitespace = data.group(1)
273+
selector = '%s' % data.group(2)
274+
command = '''%sself.submit('%s')''' % (whitespace, selector)
275+
if command.count('\\"') == command.count('"'):
276+
command = command.replace('\\"', '"')
277+
seleniumbase_lines.append(command)
278+
continue
279+
243280
# Handle .find_element_by_css_selector() + .send_keys()
244281
data = re.match(
245282
r'''^(\s*)driver\.find_element_by_css_selector\(\"([\S\s]+)\"\)'''
@@ -384,6 +421,22 @@ def main():
384421
seleniumbase_lines.append(command)
385422
continue
386423

424+
# Handle .find_element_by_xpath() + .submit()
425+
data = re.match(
426+
r'''^(\s*)driver\.find_element_by_xpath\(u?\"([\S\s]+)\"\)'''
427+
r'''\.submit\(\)\s*$''', line)
428+
if data:
429+
whitespace = data.group(1)
430+
xpath = '%s' % data.group(2)
431+
uni = ""
432+
if '(u"' in line:
433+
uni = "u"
434+
has_unicode = True
435+
command = '''%sself.submit(%s"%s")''' % (
436+
whitespace, uni, xpath)
437+
seleniumbase_lines.append(command)
438+
continue
439+
387440
# Handle .find_element_by_link_text() + .click()
388441
data = re.match(
389442
r'''^(\s*)driver\.find_element_by_link_text\(u?\"([\S\s]+)\"\)'''

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
setup(
1919
name='seleniumbase',
20-
version='1.17.13',
20+
version='1.17.14',
2121
description='All-in-One Test Automation Framework',
2222
long_description=long_description,
2323
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)