Text Widget

5/22/2016

installing perl dancer in ubuntu

For installing perl dancer you need curl utility for installing curl ,
 sudo apt-get install curl

Now we can install Perl-Dancer by this command, type this command in terminal 

curl -L http://cpanmin.us | perl - --sudo Dancer2 
 
 

creating first go program

for creating go program open your editor and paste this code, and save it as filename.go for example helloworld.go

package main

import "fmt"

func main() {
    fmt.Println("Hello, 世界")
}

I will explain these codes in details for now , we will look how to run these code.

to run type go run helloworld.go  in terminal , we get


you can try golang online as well , golang

installing go in ubuntu

Installing gccgo-go package on Ubuntu 14.04 (Trusty Tahr) is as easy as running the following command on terminal:

sudo apt-get update
sudo apt-get install gccgo-go

To check the version type go version in terminal .

creating python django project

If you installed and configured python django you can create django project .

for that create a folder any where in you system and open you terminal navigate to that folder and type the django command django-admin startproject projectname  for example django-admin startproject firstdjangoproject     


This command will create a folder firstdjangoproject        , navigate inside to the project folder . You can see file structure of django project

I will explain each of this files in detail for now lets run the application

for running the application need to type this command in your terminal

python manage.py runserver  

Ignore the migration exception , we can see the application running at localhost port 8000, 8000 is the default port . Now open your web browser and type address http://127.0.0.1:8000 and you can see

if you see this your django application is up and running and you are good to go.
press ctrl+c keys to stop the server.

python django installation on ubuntu

If you wish to install Django using the Ubuntu repositories, the process is very straight forward.

First, update your local package index with apt, and then install the python-django package:
sudo apt-get update
sudo apt-get install python-django
You can test that the installation was successful by typing:
django-admin --version 
 
If you wish to install the latest version of Django globally, a better option is to use pip, the Python package manager. First, we need to install the pip package manager. Refresh your apt package index:
sudo apt-get update
Now you can install pip. If you plan on using Python version 2, install using the following commands:
sudo apt-get install python-pip
Now that you have pip, we can easily install Django. If you are using Python 2, you can type:
sudo pip install django

You can verify that the installation was successful by typing:
django-admin --version 
 

5/19/2016

xpath

It is very easy if you understood the funta behind XPATH . xpath is XML path , XPath is used to navigate through elements and attributes in an XML document . As i said earlier both HTML and XML follows DOM structure , so we can use xpath to navigate elements and attributes in an HTML.

<html>
 <body>
   <div class="1">
     <div class="2"></div>
        <div class="1"></div>
        <div class="2">
           <div class="1">
              <a id="1">HI</a>
              <a id="2">
                 <h1>HI<h2>
              </a>
           </div>
        </div>
        <div class="3"></div>
     <div class="2"></div>
   </div>
 </body>
</html>

we can visualize the above HTML code in DOM structure we get

In Document object Model (DOM) , document is the parent object , then comes html,body,child and siblings , if we want to navigate to element h1, we can start from html inside the document , document is the outer cover of all elements.

if we want to reach body we can write its as
navigate so far (xpath) : /html/body        

Inside body  tag there is only one child which is a div element so we can write it as
navigate so far (xpath) : /html/body/div          

Inside the div element there are three div elements , so we can count it as 1,2,3 other wise returns 3 element array of div elements and we want to navigate to second div element , we can write it as

navigate so far (xpath) : /html/body/div/div[2]

Inside div[2] there is only one child which is a div element, so we can write it as 
navigate so far (xpath) : /html/body/div/div[2]/div 

Inside the div element we can see  two anchor elements and we can count it as 1,2 other wise which will return array of two anchor elements . Then we want to navigate to the second anchor element which we can write it as


navigate so far (xpath) : /html/body/div/div[2]/div/a[2]

Inside a[2] there is only one child that is the h1 , thats our required element and we can write it as 

 navigate so far (xpath) : /htm/body/div/div[2]/div/a[2]/h1

That is how xpath is take. There are two types of xpath 

  1. Absolute xpath 
  2.  Relative xpath
The above xpath we took earlier is called absolute path which contains the whole path . But there is problem in taking the absolute path because if there any change in dom will effect the navigation for example

In the above xpath /htm/body/div/div[2]/div/a[2]/h1   div[2] changes to div[1] or deleted the navigation will not work, this is where relative xpath come in to play

if we want to take the relative path of  the above absolute path , we can write it as .//a[@id='2']/h1      or .//*[@id='2']/h1     we will break this expressions in to parts 

[@id=2] , which means take any element in the document who has the id=2, in xpath attributes are represented by @id which has a value of 2 which is enclosed by two square brackets if you remember JS syntax.

so we can write it as [@id=2] and if we write a[@id='2']     this expression will return anchor tag <a> who has the attribute id=2 . 

if we write a[@id='2']/h1   this will returns the element who has path match with this expression which has h1 after a[@id='2']

if we write  //a[@id='2']/h1  the two forwarded slash means ,Selects nodes in the document from the current node that match the selection no matter where they are.

if we write .//a[@id='2']/h1   the dot in front of this means , Select the current node.


if we write *[@id='2']/h1  , There is an Asterisk comes in front of the squares means , There can be any elements comes , we wont mind the element , since id is unique and it is related with the <a> tag, it always returns the anchor element. thus we get .//*[@id='2']/h1


But when you write the expression we need to begin from left.

Now we can write path expressions using predicate which is supported by xpath.
for example [@id='2', predicates always enclosed in a square brackets . There are many other predicate which supports path expression .

for example div[2]  2 is a predicate , we can use last(),position(),@ for selecting attributes which i already said.

if we want to use predicate last() and position() we can use like this 

.//a[last()]/h1 this means , select the last anchor element in this path that is a[2] 

by predicate position we can write it as .//a[position()>1]/h1  which is a[2]
you can generate any kind of meaningful expression by mix and match this predicates.

5/18/2016

locating webelements using selenium


Record and playback is a Novice routine and I am not interested in it.

 Selenium provides several options to locate Web Elements such as (h1,p,div...) .

The attributes id,name,classname are used for identifying particular element inside html for example

<html>
 <body>
    <p id="para1">Hi</p>
    <input type=textarea name="text" >
    <p class="para2">Hello</p>
    <p class="para2">World</p>
    <a id="linkone">link1</a>
 </body>
<html>

#para1 {
  color: blue;
}
.para2 {
 color: green;
}

we are giving id to <p id="para1">  for identify the element in order to change the property of that element. if you are using css or javascript id cannot be repeated unlike class="para2" , class name can be repeated and name is the attribute of input . In selenium there are classes and methods to get these elements by passing this id,name and classname 

In selenium we can write it as :

for id : WebDriver.findElement(By.id("para1"))    , this will return a particular element.

for class : WebDriver.findElement(By.className("para2"))   , this will return all the elements which has the classname which would be a array of elements.

for nameWebDriver.findElement(By.name("text"))  , this will return the particular element .

for css : WebDriver.findElement(By.cssSelector("#para1 or . para2"))      ,  if you are giving #para1 it will return single element as like id , if you are giving .para2 this will return 2 element which is an array of elements.

for link : WebDriver.findElement(By.linkText(""))   , this will return the link which contains the text "link1"

for tagname : WebDriver.findElement(By.tagName("p"))   , this will return all the paragraph tag elements.

for patialLink : WebDriver.findElement(By.partialLinkText("link1"))  , this is same as the link but the difference is text contains a partial link.
   
for  xpath : WebDriver.findElement(By.xpath("/html/body/p"))    , this will return a element or array of elements . i will explain xpath in more in coming post.