0

Does someone know the difference between those 2 keywords from Selenium:

element.submit()

element.submit

I've some forms working with the first one, and others working with the second.

For example,

self.webdriver.find_element_by_xpath('//*[@id="search"]/input').submit

return a result while

self.webdriver.find_element_by_xpath('//*[@id="search"]/input').submit()

returns another.

Thanks!

2
  • Can you update the question with some working example of element.submit? Commented May 23, 2018 at 13:10
  • What do you mean by "self.webdriver.find_element_by_xpath('//*[@id="search"]/input').submit return a result" ? What result? Everything might "return a result"... Can you put more meaning into your question? Commented May 23, 2018 at 13:42

2 Answers 2

1

As per the current API Docs of selenium.webdriver.remote.webelement the method submit() is defined as follows :

submit()
    Submits a form.

As per the source code, submit() looks for the ancestor-or-self as form, creates an event and dispatches. In case of failure Command.SUBMIT_ELEMENT is executed.

Source Code :

def submit(self):
    """Submits a form."""
    if self._w3c:
        form = self.find_element(By.XPATH, "./ancestor-or-self::form")
        self._parent.execute_script(
            "var e = arguments[0].ownerDocument.createEvent('Event');"
            "e.initEvent('submit', true, true);"
            "if (arguments[0].dispatchEvent(e)) { arguments[0].submit() }", form)
    else:
        self._execute(Command.SUBMIT_ELEMENT)

So, it's apparent that submit() is the full proof approach to follow though in some cases submit may also cater to your needs. But following the Best Practices submit must be avoided.

Sign up to request clarification or add additional context in comments.

Comments

0

In python functions and methods are first-class objects. We can call them by using some parentheses (brackets) on the end.

But sometimes we don't want to call them, we just want to pass a reference to the callable(function) itself, In those cases, we can simply avoid using parentheses.

Therefore, whenever you are using the function, then we must use parentheses. And whenever we need to pass this method as argument to some other method, then we can omit parentheses.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.