1. Creating New Instance Of Firefox Driver
WebDriver driver = new FirefoxDriver();
Above given syntax will create new instance of Firefox driver.
2. Command To Open URL In Browser
2. Command To Open URL In Browser
driver.get("http://only-testing-blog.blogspot.com/2013/11/new-test.html");
This syntax will open specified URL of software web application in web
browser.
3. Clicking on any element or button of webpage
driver.findElement(By.id("submitButton")).click();
Above given syntax will click on targeted element in webdriver.
4. Store text of targeted element in variable
4. Store text of targeted element in variable
String dropdown =
driver.findElement(By.tagName("select")).getText();
This syntax will retrieve text from targeted element of software web application
page and will store it in variable = dropdown.
5. Typing text in text box or text area.
5. Typing text in text box or text area.
driver.findElement(By.name("fname")).sendKeys("My
First Name");
Above syntax will type specified text in targeted element.
6. Applying Implicit wait in webdriver
6. Applying Implicit wait in webdriver
driver.manage().timeouts().implicitlyWait(15,
TimeUnit.SECONDS);
This syntax will force webdriver to wait for 15 second if element not
found on page of software web application.
7. Applying Explicit wait in webdriver with WebDriver canned conditions.
7. Applying Explicit wait in webdriver with WebDriver canned conditions.
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//div[@id='timeLeft']"),
"Time left: 7 seconds"));
Above 2 syntax will wait for till 15 seconds for expected text
"Time left: 7 seconds" to be appear on targeted element.
8. Get page title in selenium webdriver
8. Get page title in selenium webdriver
driver.getTitle();
It will retrieve page title and you can store it in variable to use in
next steps
9. Get Current Page URL In Selenium WebDriver
9. Get Current Page URL In Selenium WebDriver
driver.getCurrentUrl();
It will retrieve current page URL and you can use it to compare with
your expected URL.
10. Get domain name using java script executor
JavascriptExecutor javascript =
(JavascriptExecutor) driver;
String
CurrentURLUsingJS=(String)javascript.executeScript("return
document.domain");
Above syntax will retrieve your software application's domain name using
webdriver's java script executor interface and store it in to variable.
11. Generate alert using webdriver's java script executor interface
JavascriptExecutor javascript =
(JavascriptExecutor) driver;
javascript.executeScript("alert('Test Case
Execution Is started Now..');");
It will generate alert during your selenium webdriver test case
execution.
12. Selecting or Deselecting value from drop down in selenium webdriver.
·
Select By Visible Text
Select mydrpdwn = new
Select(driver.findElement(By.id("Carlist")));
mydrpdwn.selectByVisibleText("Audi");
It will select value from drop down list using visible text value =
"Audi".
·
Select By Value
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.selectByValue("Italy");
It will select value by value = "Italy".
·
Select By Index
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.selectByIndex(0);
It will select value by index= 0(First option).
Deselect by Visible Text
Deselect by Visible Text
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectByVisibleText("Russia");
It will deselect option by visible text = Russia from list box.
·
Deselect by Value
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectByValue("Mexico");
It will deselect option by value = Mexico from list box.
·
Deselect by Index
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectByIndex(5);
It will deselect option by Index = 5 from list box.
·
Deselect All
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectAll();
It will remove all selections from list box of software application's
page.
·
isMultiple()
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
boolean value = listbox.isMultiple();
It will return true if select box is multiselect else it will return
false.
13. Navigate to URL or Back or Forward in Selenium Webdriver
13. Navigate to URL or Back or Forward in Selenium Webdriver
driver.navigate().to("http://only-testing-blog.blogspot.com/2014/01/textbox.html");
driver.navigate().back();
driver.navigate().forward();
1st command will navigate to specific URL, 2nd will navigate one step
back and 3rd command will navigate one step forward.
14. Verify Element Present in Selenium WebDriver
14. Verify Element Present in Selenium WebDriver
Boolean iselementpresent =
driver.findElements(By.xpath("//input[@id='text2']")).size()!= 0;
It will return true if element is present on page, else it will return
false in variable iselementpresent.
15. Capturing entire page screenshot in Selenium WebDriver
15. Capturing entire page screenshot in Selenium WebDriver
File screenshot =
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new
File("D:\\screenshot.jpg"));
It will capture page screenshot and store it in your D: drive.
16. Generating Mouse Hover Event In WebDriver
16. Generating Mouse Hover Event In WebDriver
Actions actions = new Actions(driver);
WebElement moveonmenu =
driver.findElement(By.xpath("//div[@id='menu1']/div"));
actions.moveToElement(moveonmenu);
actions.perform();
Above example will move mouse on targeted element.
17. Handling Multiple Windows In Selenium WebDriver.
17. Handling Multiple Windows In Selenium WebDriver.
1.
Get All Window Handles.
Set<String> AllWindowHandles =
driver.getWindowHandles();
2.
Extract parent and child window handle from all
window handles.
String window1 = (String)
AllWindowHandles.toArray()[0];
String window2 = (String)
AllWindowHandles.toArray()[1];
3.
Use window handle to switch from one window to
other window.
driver.switchTo().window(window2);
Above given steps with helps you to get window handle and then how to
switch from one window to another window.
18. Check Whether Element is Enabled Or Disabled In Selenium Web driver.
boolean fname =
driver.findElement(By.xpath("//input[@name='fname']")).isEnabled();
System.out.print(fname);
Above syntax will verify that element (text box) fname is enabled
or not. You can use it for any input element.
19. Enable/Disable Textbox During Selenium Webdriver Test Case Execution.
19. Enable/Disable Textbox During Selenium Webdriver Test Case Execution.
JavascriptExecutor javascript =
(JavascriptExecutor) driver;
String todisable =
"document.getElementsByName('fname')[0].setAttribute('disabled',
'');";
javascript.executeScript(todisable);
String toenable =
"document.getElementsByName('lname')[0].removeAttribute('disabled');";
javascript.executeScript(toenable);
It will disable fname element
using setAttribute() method and enable lname element
using removeAttribute() method.
20. Selenium WebDriver Assertions With TestNG Framework
·
assertEquals
Assert.assertEquals(actual, expected);
assertEquals assertion helps you to assert actual
and expected equal values.
·
assertNotEquals
Assert.assertNotEquals(actual, expected);
assertNotEquals assertion is useful to assert not
equal values.
·
assertTrue
Assert.assertTrue(condition);
assertTrue assertion works for boolean value true assertion.
·
assertFalse
Assert.assertFalse(condition);
assertFalse assertion works for boolean value false
assertion.
21. Submit() method to submit form
driver.findElement(By.xpath("//input[@name='Company']")).submit();
It will submit the form.
22. Handling
Alert, Confirmation and Prompts Popups
String myalert =
driver.switchTo().alert().getText();
To store alert text.
driver.switchTo().alert().accept();
To accept alert.
driver.switchTo().alert().dismiss();
To dismiss confirmation.
driver.switchTo().alert().sendKeys("This Is
John");
To
type text In text box of prompt popup.
============================================
ReplyDeleteAmazing, thanks a lot my friend, I was also siting like a your banner image when I was thrown into Selenium.
When I started learning then I understood it has got really cool stuff.
I can vouch webdriver has proved the best feature in Selenium framework.
thanks a lot for taking a time to share a wonderful article.
Best Selenium Training Institute in Chennai
Selenium Training in Velachery
Wow, really very good information and very helpful for make a good career.As per my opinion Every IT industry, where the developers build new codes, need Selenium platform to test and rectify the newly formed codes. This is where a well-trained professional in this aspect is necessary to offer the expertise of checking the codes in automation checking frameworks. recently I also complete my selenium web driver online training through online Seleniumlabs", and this training center really good and I learned much more things and now become an eminent tester in the IT industry.
ReplyDeleteThank you
Good. Congratulations...
DeleteThanks
I really appreciate this post and I like this very much. I am waiting for new post here and Please keep it up in future..
ReplyDeleteSoftware Testing Services
Functional Testing Services
Test Automation Services
QA Automation Testing Services
Regression Testing Services
API Testing Services
Compatibility Testing Services
Performance Testing Services
Security Testing Services
Software Testing Company
Software Testing Services in USA
Software Testing Companies in USA
Finding the time and actual effort to create a superb article like this is great thing. I’ll learn many new stuff right here! Good luck for the next post buddy..
ReplyDeleteSoftware Testing Services
Software Testing Services in India
Software Testing Companies in India
Software Testing Services in USA
Software Testing Companies in USA
Software Testing Companies
Software Testing Services Company
QA Testing Services
Aw, this was a really nice post! I would like to thank you for the efforts you’ve put in writing this site. Best of luck for the next! Please visit my web site worthmap.com. Best Wealth Tracking Software service provider.
ReplyDeleteIn Deer Park & Craigieburn, Gill Driving School offers lesson with suitable range of packages as per yours need to pass the 1st Vic Road test.
ReplyDeletedriving test Deer Park
driving school Deer Park
Thanks for making this blog helpful for me! I am doing online QA Software Testing Training & Certification I would like to thank for the efforts you have made in writing this post. Thanks for sharing.
ReplyDeleteYour blog has wonderful information regarding software Testing, I also have some valuable information regarding the Best Software Testing Services in USA, Canada and India hopefully, this will be very helpful for you.
ReplyDeleteThe most popular public safety options, with rectangular or oval structures and MS or stainless steel side panels. Automatic safety sensors, BMS integration fire alarms, and easy third-party control access may all be added to flap barriers. Get in contact with our knowledgeable team of persons below to learn more about the specific goods or to schedule a free consultation for a thorough examination and professional advice.
ReplyDeleteBest automation company in India
Top automation company in Surat Gujarat
Thank you so much for sharing your knowledge. Keep it.
ReplyDeletebest digital marketing services in vellore india
seo services company in vellore india
responsive web design company vellore india
hybrid mobile application development company vellore india
Android App Development Company in Vellore india
Good to see such a nice blog post Best Software quality assurance services in USA
ReplyDeleteLc Highway Is The World's First Biggest Platform Where Anyone Can Read & Write Career Reviews Freely And Book Counsellors With A Money-Back Warranty System. Lc Highway Is Also Helping Students By Providing Other Aspects Like Comparing Career, Career Tests, Career Games, Career Reports And Also Availing Career Camps In Schools. Lc Highway Is An Initiative To Help The Education Sector And Also Provide A Platform Where People Can Discuss Their Career Success In The Form Of Career Reviews.
ReplyDeleteGreat blog! This is really helpful for my reference.
ReplyDeletewhat is DevOps engineer
Who is a DevOps engineer
Great Post. Very informative. Keep Sharing!!
ReplyDeleteApply Now for Software Testing Training in Noida
For more details about the course fee, duration, classes, certification, and placement call our expert at 70-70-90-50-90
Very informative content. Explained clearly about software testing commands. Software testing playing a important role in major software development company. Also checkout more about software testing services and how it's helps software development process. Keep sharing more content like this.
ReplyDeleteI am really very happy to visit your blog. Directly I am found which I truly need. please visit our website for more information
ReplyDeleteQuality Engineering Services in USA
This one is the best blog i found on this topic most attracting part is the way of information you stuffed in this blog. If you are searching for best expert industrial training for automation testing courses join Ducat Today. Call on 7070905090
ReplyDeleteThis post is so useful and informative. Keep updating with more information.....
ReplyDeleteDeveloper Testing
Software System Testing
Hi here,
ReplyDeleteThanks for sharing your blog. It was really good. If you're looking for Best Staffing Company in Noida
then you must consider Insbytech noida. They are committed to providing clients with I.T. Solutions that work With 10+ years of experience and a diverse portfolio, insbytech is able to cater and design services for most businesses.
Thank you for Sharing!!
ReplyDeletePrancer specialize in cloud security and compliance through validation frameworks. Contact us today.
kralbet
ReplyDeletebetpark
tipobet
slot siteleri
kibris bahis siteleri
poker siteleri
bonus veren siteler
mobil ödeme bahis
betmatik
YHZE
Selenium is an open-source software testing framework for automating web application testing. It validates web applications and checks compatibility issues across different platforms to determine whether they function correctly. Developers and testers use multiple programming languages, including Java, Python, Ruby, etc., to write Selenium test scripts that help them automate interactions
ReplyDeletewith a web browser.
it is an informative and helpful for us.
ReplyDeleteIndustrial Services
It is an interesting article and informative moreover you are doing a good work keep it up.
ReplyDeleteCambridge airport taxi
This comment has been removed by the author.
ReplyDelete