Selenium Webdriver Submit() VS Click()

Selenium Webdriver submit() vs click()

The submit() function is there to make life easier. You can use it on any element inside of form tags to submit that form.

You can also search for the submit button and use click().

So the only difference is click() has to be done on the submit button and submit() can be done on any form element.

It's up to you.

http://docs.seleniumhq.org/docs/03_webdriver.jsp#user-input-filling-in-forms

Robot Framework Click Button vs Submit Form

You definitely should not use sleep since it introduces artificial delays that may make your whole suite slower than it needs to be. I personally also thing Wait until keyword succeeds should almost never be used. It litters the log with messages as it retries. Plus, I think it masks problems instead of fixing them.

The answer is to use one of the wait keywords. You say you can't use Wait Until Page Contains ""because I don't know, whether login page will be loaded again with some error message or Dashboard page loaded in success". I don't understand that reasoning.

Your application should be deterministic. That is, if you enter correct login credentials than you should be guaranteed that it will go to the dashboard page, and if you enter the wrong conditions you should see an error and/or be redirected back to the login page.

The point of the test is to verify those conditions. So, for a test that verifies whether you get the dashboard page or not, you should find an element on the dashboard page and wait for it to be visible after submitting the form. If it doesn't appear in the proper amount of time, your test should throw an error.

Personally I recommend using page objects. The library I wrote [1], for example, has a mechanism to wait for a page refresh, and assertions to verify you are on the page you think you should be on. You don't need to use my library though -- the core of the code is only a couple hundred lines of code, so it's easy to write your own.

[1] https://github.com/boakley/robotframework-pageobjectlibrary

Clicking submit button using Selenium

Induce WebDriverWait And element_to_be_clickable() And following xpath option.

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn-fantasy green big' and @type='submit'][contains(.,'Iniciar sesión')]"))).click()

OR Css selector.

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn-fantasy.green.big[type='submit']"))).click()

You need to imports following.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

Apart from click() and submit() method is there any other way to select/click a web element in selenium Webdriver?

If you want to click something, why would you use something else? I guess click() is the best method for elements to be clickable.

Still you can use enter to perform the same.

WebElement button = driver.findElement(By.id(""));
button.sendKeys(Keys.Enter);

Unable to click submit button using selenium- Java

Use WebDriverWait() wait for elementToBeClickable() and following xpath.

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(.,'Log In')]"))).click();

OR

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='AnimatedForm__submitButton m-full-width' and @type='submit']"))).click();


Related Topics



Leave a reply



Submit