driver = new FirefoxDriver();
driver.get("http://www.google.com");
driver.findElement(By.id("gbqfq")).sendKeys("Selenium");
Thread.sleep(1500L);
driver.findElement(By.id("gbqfb")).click();
Thread.sleep(1500L);
List<WebElement> linkElements = driver.findElements(By.xpath("//h3[@class='r']/a"));
for(int i=0;i<=linkElements.size();i++)
{
String text = linkElements.get(i).getText();
driver.findElement(By.linkText(text)).click();
Thread.sleep(2000L);
System.out.println("Title of link\t:\t" + driver.getTitle());
Thread.sleep(2000L);
driver.navigate().back();
linkElements = driver.findElements(By.xpath("//h3[@class='r']/a"));
}
---------------
//Normal imports
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ClickaLink {
public static void main(String[] args) {
//Creating the web driver
WebDriver fd=new FirefoxDriver();
//Step 1&2
fd.get("http:\\google.com");
fd.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
//Step-3
fd.findElement(By.xpath("//input[@class='gbqfif']")).sendKeys("askqtp");
//step-4
fd.findElement(By.xpath("//*[@id='gbqfb']")).click();
WebElement box=fd.findElement(By.xpath("//*[@id='res']"));
//the center box in the results page that has all the links Step-5
List<WebElement>allLinks=box.findElements(By.xpath("//*[@id='rso']/li/div/h3/a"));
//xpath of the links displayed
System.out.println("Total Links -->" allLinks.size());
for(int i=1;i<allLinks.size();i++ ){
System.out.println(allLinks.get(i).getText());
//Step-6
allLinks.get(1).click();
//click on the first link that is displayed
}
}
---------
// You get all links in a list
List<WebElement> linkElements = driver.findElements(By.xpath("//h3/a"));
// for each element(link) you click() on it
for(WebElement elem: linkElements)
{
elem.click();
// i suggest to put a wait right there
System.out.println("Title of link\t:\t" + driver.getTitle());
driver.navigate().back();
}
-----------------
Element.RaiseEvent("onmousedown")
System.Threading.Thread.Sleep(5000);
------------
selenium.mouseDownAt("//div/div[4]/div/div/img","10,10");
selenium.mouseUpAt("//div/div[4]/div/div/img","10,10");
Actually the xpath for the image cna be as shown below as the img has src attribute.
selenium.mouseDownAt("//img[@src='Resources/refresh.png']","10,10");
selenium.mouseUpAt("//img[@src='Resources/refresh.png']","10,10");
---------------------
Locatable hoverItem = (Locatable) driver.findElement(srating1);
Mouse mouse = ((HasInputDevices) driver).getMouse();
mouse.mouseMove(hoverItem.getCoordinates());
To do the hover for the first star then repeat.
The for the last item you should be able to do what you are doing or try
Locatable clickItem = (Locatable)driver.findElement(srating3).getLocation();
clickItem.getCordinates(clickItem).click();
-----------------------
int rowcount = driver.FindElements(By.Id("someid")).Count;
for (int i = 0; i < rowcount; i++)
{
//Finding App name based on user entered text
var elems = driver.FindElements(By.PartialLinkText(text));
IList<IWebElement> list = elems;
for (int j = 0; j < list.Count; j++)
{
var table = driver.FindElement(By.Id("someid"));
IList<IWebElement> rows = table.FindElements(By.TagName("tr"));
IList<IWebElement> cells = rows[i].FindElements(By.TagName("td"));
//Again finding element based on user entered text
var elem = driver.FindElements(By.PartialLinkText(text));
list = elem;
if (list[1].Text.Equals(text))
{
list[0].Click();
string duration;
string price;
var elements = driver.FindElements(By.Id("SPFieldNumber"));
IList<IWebElement> lists = elements;
duration = lists.First().Text.ToString();
price = lists.ElementAt(1).Text.ToString();
MessageBox.Show(duration);
MessageBox.Show(price);
driver.Navigate().Back();
}
}
}
-----------
var text_input = Driver.Instance.FindElement(By.Id("text_input"));
if (!String.IsNullOrEmpty(text_input.GetAttribute("value"))) {
var button_Save = Driver.Instance.FindElement(By.Id("submit"));
button_Save.Click();
} else {
// if you want to do something
}
-------------------------------
driver.FindElement(By.XPath("//input[@name='tagName']")).Clear(); - not working
driver.FindElement(By.XPath("//input[@name='tagName']")).SendKeys(tagName); - not working
driver.FindElement(By.Id("tagName")).SendKeys(Keys.Control); - not working
driver.FindElement(By.Id("tagName")).Clear(); - not working
driver.FindElement(By.Id("tagName")).SendKeys(tagName); - not working
--------------------
public void GoogleSearch()
{
//Navigate to the site
driver.Navigate().GoToUrl("http://www.google.com.au");
// Find the text input element by its name
IWebElement query = driver.FindElement(By.Name("q"));
// Enter something to search for
query.SendKeys("Selenium");
// Now submit the form
query.Submit();
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 5 seconds
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
wait.Until((d) => { return d.Title.StartsWith("selenium"); });
//Check that the Title is what we are expecting
Assert.AreEqual("selenium - Google Search", driver.Title);
}
}
}
---------------
// You may use any WebDriver implementation. Firefox is used here as an example
WebDriver driver = new FirefoxDriver();
// A "base url", used by selenium to resolve relative URLs
String baseUrl = "http://www.google.com";
// Create the Selenium implementation
Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
// Perform actions with selenium
selenium.open("http://www.google.com");
selenium.type("name=q", "cheese");
selenium.click("name=btnG");
// And get the underlying WebDriver implementation back. This will refer to the
// same WebDriver instance as the "driver" variable above.
WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getUnderlyingWebDriver();
-----------------
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.IE;
namespace Selenium1
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Selenium Test Project - 1");
So first of all we will create an instance of Internet Explorer Driver.
IWebDriver driver = new InternetExplorerDriver();
Specify the URL to which we want to navigate.
driver.Navigate().GoToUrl("http://www.google.com");
Find the element by its input name. You can check this by viewing the source code of the webpage.
IWebElement query = driver.FindElement(By.Name("q"));
Enter the keyword for which you want to do the search.
query.SendKeys("Selenium");
Now submit the keyword.
query.Submit();
Wait for 10 seconds to get the page loaded.
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
wait.Until((d) => { return d.Title.ToLower().StartsWith("Selenium");});
This will display the page title in the console.
System.Console.WriteLine("Page Title is: "+ driver.Title);
Close the IE browser.
driver.Quit();
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
---------------------------
http://mestachs.wordpress.com/2012/08/13/selenium-best-practices/
----------------------
public
static
void
BingSearchForSelenium()
{
using
(IWebDriver driver =
new
InternetExplorerDriver(
@"C:\Users\olpower\Documents\Selenium"
))
{
driver.FindElement(By.Name(
"q"
)).SendKeys(
"Selenium"
);
driver.FindElement(By.Name(
"go"
)).Click();
}
}
Hiç yorum yok:
Yorum Gönder