Upload file or image using Selenium Webdriver in C#

Here is the code that you can use to Upload file or image using Selenium Webdriver in C#
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("document.getElementsByName('userfile')[0].style.display='block';");
IWebElement element = driver.FindElement(By.Name("userfile"));
element.SendKeys("image file path");

Example of verifyTextPresent in Webdriver

Here is another example which takes in a WebElement and searches the text of elements with particular tags

public boolean verifyTextPresent(WebElement rootElement, String tag, String text) {
List elements = rootElement.findElements(By.tagName(tag));
boolean match = false;
for (WebElement elem : elements){
String elementText = elem.getText();
if (elementText.contains(text)){
match = true;
break;
}
}
try {
Assert.assertTrue(match);
System.out.println("\"" + text + "\" was found within elements within the passed in WebElement with ID (" + rootElement.getAttribute("id")+ ")");
}
catch (Exception e) {
System.err.println("\"" + text + "\" not found within elements within the passed in WebElement with ID (" + rootElement.getAttribute("id")+ ")");
}
return match;
}

Submitted By: Daniel

Selenium the Agile automation testing tool

Test automation is usually lagging behind development of new functionality. The tools that are used to automate are dependent on the UI and this causes automation of the functionality to start only after the environment and the UI are stable.

Selenium is the test automation tool that helps test below the UI layer. The automation can be done earlier even before the UI is completely ready or matured.

Selenium is language independent and this makes to unique as testers/ developers can start coding as they code the application. You can code the Selenium automation scripts in PHP, Java, C#, Ruby, Python. Selenium uses locator – an element locator on a webpage to identify the element on the webpage.

Ideally its good to code the test scripts in the language the web application is built; by doing so you can integrate the test scripts in your nightly build and help speed up the QA process.

If you found this solution helpful or have something extra to add, feel free to share it here by commenting below.

Selenium 2.2.0 & Python installation guide on Linux

Here is the guide to install and using Selenium Webdriver and Python on Ubuntu Linux 11.04.
OS: Ubuntu 11.04
1. Verify version of Java is greater than version 1.5, use command:-
$ java –version
If java needs to be installed, use the following command:-
$ sudo apt-get install sun-java6-jre

2. Version of Python is 2.7x, use following command to display version on machine:-
$ python –version
If python needs to be installed, use the following command:-
$ sudo apt-get install python

3. We need to install ‘pip’ – a tool for managing Python packages, use the following command to install pip:-
$ sudo apt-get install python-pip

4. We now need to install the Selenium bindings for Python to use the Selenium API, use the following command to install Selenium:-
$ sudo pip install selenium

5. We can now create the following test example, using a text editor, save as test1.py:-
#!/usr/bin/env python

import unittest
from selenium import webdriver
class TestSeleniumWikiTitle(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
def testTitle(self):
self.browser.get('http://www.seleniumwiki.com/')
self.assertIn('Selenium Tips, Webdriver Tips, C# Selenium Examples, Java Selenium Example, Selenium2 Webdriver, Selenium Web Testing Guide', self.browser.title)
def tearDown(self):
self.browser.quit()
if __name__ == '__main__':
unittest.main()

6. To execute the test, use the following command:-
$ python test1.py

Submitted by Barry Horgan