Problem: Selenium when you start Firefox, you use a new profile as the startup profile, which is not available in Firefox settings manually.
Workaround: Locate the profile directory when Firefox is manually started and pass Firefoxprofile to Webdriver in the test program
1. View the profile directory
command line, go to the Firefox installation directory (more: C:\Program Files (x86) \mozilla Firefox), execute
Firefox.ext-p
Or
Firefox.exe-profilemanager
The Profile management screen pops up and the mouse moves to the profile name, showing its path
You can also create a new profile directory, start the profile's Firefox from this dialog box, and set up a trusted site
2. Test procedure:
1 @Test2 Public voidTest () {3System.setproperty ("Webdriver.gecko.driver", "E:/selenium/geckodriver.exe");4 5 //the profile directory that points to Firefox6Firefoxprofile profile =NewFirefoxprofile (NewFile ("C:/users/me/appdata/roaming/mozilla/firefox/profiles/mmi7kyn4.default"));7Profile.setacceptuntrustedcertificates (true);8 9 //start with the specified profileTenWebdriver Driver =Newfirefoxdriver (profile); OneDriver.get ("https://www.abcd.com"); A - //Enter user name, password, and submit -Webelement userId = driver.findelement (By.cssselector ("Input[name= ' userid ')")); theUserid.sendkeys ("username"); -webelement password = driver.findelement (By.cssselector ("input[name= ' password ']")); -Password.sendkeys ("Pasword"); - +Webelement submit = Driver.findelement (By.cssselector ("button")); - Submit.click (); + A //wait for the answer slightly at Try { -Thread.Sleep (3000); -}Catch(interruptedexception e) { - e.printstacktrace (); - } - inAssert.assertequals ("XXX", Driver.gettitle ()); - driver.quit (); to}
A few ways to delay the wait:
1) Thread.Sleep (), the stupidest method, but sometimes very practical
2) Implicit wait, when you want to find the element does not appear immediately, tell Webdriver query dom for a certain time. The default value is 0, but after the setting, the time will work for the entire life cycle of the Webdriver object instance.
Webdriver dr = new Firefoxdriver ();
Dr.manage (). Timeouts (). implicitlywait (Timeunit.seconds);
3) using JavaScript
webelement element = driver.findelement (By.xpath (test));
((Javascriptexecutor) driver). Executescript ("arguments[0].style.border=" 5px Solid Yellow "", Element);
4) display wait, recommended use.
webdriverwait wait = new Webdriverwait (DR, 10);
Wait.until (expectedconditions.visibilityofelementlocated (by.id ("kw"));
Explicitly waiting for a condition that can be customized for more complex page-waiting conditions
(1) Elements available and can be clicked: Elementtobeclickable (by locator)
(2) element is selected: elementtobeselected (webelement Element)
(3) Element exists: presenceofelementlocated (by locator)
(4) The element contains a specific text: Texttobepresentinelement (by locator)
(5) page element value: Texttobepresentinelementvalue (by locator, java.lang.String text)
(6) Title: Titlecontains (java.lang.String title)
Reference Address:
Http://www.cnblogs.com/lelelong/p/5523444.html
Http://blog.sina.com.cn/s/blog_71bc9d680102wr4o.html
Selenium study Notes (2) Testing HTTPS websites