简体   繁体   中英

Ruby - Form doesn't submit to the right page in Selenium-Webdriver

I am attempting to write some automated tests for a client my company has been working for. One of these tests is to have Selenium-WebDriver enter a username and password and login. When I do that manually as a human user, I get redirected to the right page (the base url page) and get logged in successfully. However, if I have Selenium-WebDriver do it, the page gets redirected to /users/:id and a 404 error occurs.

I have pasted the code in its most basic form below. I think the issue is due to page redirects but I can't be sure. (This is a rails project, the automated test is external.) I have tried adding delays, I've tried adding waits, and I've even tried slowing WebDriver down to solve this issue. Nothing seems to work. I don't know how to add a wait directly into the click function of the submit button. If anyone has any further ideas, that would be great.

require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
driver.navigate.to ''
driver.find_element(:id, 'user_email').send_keys ''
driver.find_element(:id, 'user_password').send_keys ''
driver.find_element(:name, 'commit').click
sleep 5 # this is so my eyes have time to see if it worked
driver.quit

Thanks in advance!

It looks like it's a browser thing. It works in some browsers, but not others.

Thank you for your thoughts!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM