Friday, 23 September 2016

                                    SELENINUM BASISCS:
                                    -----------------------------

Pointing to the particular Element:
----------------------------------
1.  driver.findElement(By.xpath("//input[@name='fname']"));
2.  driver.findElement(By.xpath("//input[contains(@name,'fname')]"));
3.  input[@id='email']/parent::*
4.  input[@id='email']/following::*
5.  input[@id='email']/following::tr

//select[@id='month']/following-sibling::*
//select[@id='month']/following-sibling::select/
//input[@id='pass']/preceding::tr


Locators:
----------------
By ID driver.findElement(By.id(<element ID>)) Locates an element using the ID attribute
By name driver.findElement(By.name(<element name>)) Locates an element using the Name attribute
By class name driver.findElement(By.className(<element class>)) Locates an element using the Class attribute
By tag name driver.findElement(By.tagName(<htmltagname>)) Locates an element using the HTML tag
By link text driver.findElement(By.linkText(<linktext>)) Locates a link using link text
By partial link text driver.findElement(By.partialLinkText(<linktext>)) Locates a link using the link's partial text
By CSS driver.findElement(By.cssSelector(<css selector>)) Locates an element using the CSS selector
By XPath driver.findElement(By.xpath(<xpath>)) Locates an element using XPath query


Ex: Chrome driver

System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\Drivers\\chromedriver.exe");
ChromeDriver driver= new  ChromeDriver();
driver.get("http://www.google.com");
  WebElement text =driver.findElement(By.xpath("//input[@name='q']"));
        text.sendKeys("sample webdriver....");
driver.findElement(By.id("gsri_ok0")).submit();

EX:textbox
We can put values into a text box using the 'sendkeys' method. Similarly, we can also retrieve text from a text box using the getattribute("value") command.

     1. driver.findElement(By.name("cpar1")).sendKeys("10");
      Thread.sleep(10000000);
 
     2. String result = driver.findElement(By.id("cpar1")).getAttribute("value");

Ex:Radio Button
(By default if selected then using click() we can unselect
 By default if it is unselected then again using click() we can select)
We can select/unselect a check box using the 'click' method
       To can select/unselect raido button using click()
      1.driver.findElement(By.id("cpayoff1")).click();// becomes selected radio button
 To check checkbox select/unselect
      2.System.out.println("The Output of the IsSelected " + driver.findElement(By.id("cpayoff2")).isSelected());
                .isDisplayed()) or .isEnabled()


EX:CheckBox
(By default if selected then using click() we can unselect
 By default if it is unselected then again using click() we can select)

We can select/unselect a check box using the 'click' method
driver.findElement(By.id("caddoptional")).click();
 
 Ex: DropDown
 select an option using  Text,Index, Value:
 'selectByVisibleText':
           Select dropdown = new Select(driver.findElement(By.id("ccompound")));
           dropdown.selectByVisibleText("continuously");
 or 'selectByIndex' :(indexing starts from zero)
          Select dropdown = new Select(driver.findElement(By.id("ccompound")));
 dropdown.selectByIndex(1)
 or  'selectByValue' methods:
           Select dropdown = new Select(driver.findElement(By.id("ccompound")));
  dropdown.selectByValue("annually");
     

 Ex:
 <select id="ccompound" name="ccompound" style="width:80px;">
      <option value="semiannually"> semiannually </option>
                selectByValue             selectByVisibleText

</select>


Thread.Sleep
----------------

Thread.Sleep is a static wait and it is not a good way to use in scripts as it is sleep without condition.
1.Thread.sleep(1000);
2.ExplicitWait: waits until that particulart element loading
WebElement DynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("DynamicElement")));

3.ImplicitWait: Waits tills DynamicElement loading
WebElement DynamicElement = driver.findElement(By.id("DynamicElement"));


4.FluentWait:
maximum amount of time to wait for a condition to take place, as well as the frequency with which to check the existence of the object condition.

Wait wait = new FluentWait(driver).withTimeout(60, SECONDS).pollingEvery(10, SECONDS) .ignoring(NoSuchElementException.class);
   WebElement dynamicelement = wait.until(new Function<webdriver,webElement>(){
 
   public WebElement apply(WebDriver driver){
      return driver.findElement(By.id("dynamicelement"));
      }
     
   });
 
 Ex: Drag and Drop
 WebElement From = driver.findElement(By.xpath(".//*[@id='j3_7']/a"));
 WebElement To = driver.findElement(By.xpath(".//*[@id='j3_1']/a"));
 
 
Keyboard Actions
-------------------
syntax to call keyboard functions using Selenium WebDriver.
sendKeys, pressKey,releaseKey
//to input the text as "software" to the browser textbox
driver.getKeyboard().sendKeys("software");
driver.getKeyboard().pressKey("software");
driver.getKeyboard().releaseKey("software");

Mouse Events:
----------------
click(WebElement onElement)
void contextClick(WebElement onElement)//ContexClick= mouse Right Click
void doubleClick(WebElement onElement)
void mouseDown(WebElement onElement)
void mouseUp(WebElement onElement)
void mouseMove(WebElement toElement)
void mouseMove(WebElement toElement, long xOffset, long yOffset)

Multi Select Action(multi select dropdown list)
------------------------------------------------
1. select dropdown button id
2. select desired item from dropdwon list of id'sample
3. Using WebElement we can get all the multiple selected list from dropdown list


Log4j methods
----------
Log level methods used for logging the messages as one of the following:
error
warn
info
debug
log

NDName = "^SeleniumAuto" + dateAndTime

id="ENodeB_deDetails";

urtrans_id_child1

after back button
backButton

xPathacBarringForSpecialACEdit://*[@id='paramDetailsDisplay']/div/div/div[2]/div/div/table/tbody/tr[1]/td/table/tbody/tr[2]/td/table/tbody/tr/td[2]/a

[@id='help']/following::a


input[@id='help']/following::tr




<script type="text/javascript"
function checkRedirect() {   var userValue = document.getElementById('user').value;   if (userValue == "null") {    document.title = "Redirecting to Dashboard";    document.getElementById('redirect').click();   }  }
 var rootContext;
 function openMasterHelpWindow()
 {  var helppath="/pages/Help/";
 title = "Masterhelp.html";
 rootContext = $("#rootContext").attr("value");  var link = rootContext+helppath+title;  window.open(link,"Help",  "status=0, scrollbars=1, resizable=1 ,'height=' + screen.height + 'width=' + screen.width); ");  return false; }</script>

 eX:XPATHS:
 --------------

 //body/div/table/tbody/






 1. xpath=//body/div[3]/form/fieldset/select
2. xpath=//body/div[3]/form/fieldset/select[last()]
3. xpath=//body/div[3]/form/fieldset/select[@id='searchLanguage']
4. xpath=//body/div[3]/form/fieldset/select[@name='language']
5. xpath=//div[@class='search-container']/descendant::select[@name='language']
6. xpath=//select[contains(@id, "searchLanguage")]
7. xpath=//div[@class='search-container']/descendant::select[position()=1]
8. xpath=//body/div[3]/form/fieldset/select[count(*)>1]

 //*[@id='EntityContentDetails']/li/div/fieldset/div/div/div/div/div[2]/div/div/table/tbody/tr[3]/td/table/tbody/tr[4]/td/table/tbody/tr/td[2]/a

















       
     
       

No comments:

Post a Comment