Wednesday, 15 October 2014

Selenium XPath locators examples:

1.

div id="submenu_electronics" class="submenu" data-submenu-key="electronics">
    <div class="line shopby allow-overflow">
    <div class="line main-section" data-tracking-id="nmenu_sub_electronics">
        <div id="menu-electronics-tab-0-content" class="tab-content " data-tracking-id="Categories">
            <ul class="unit size1of5 menu-column even ">
                <li class="heading">


Xpath in firebug console:
$x("//div[@id='submenu_electronics' and @class='submenu']/div[2]/div/ul[1]")
or
$x("//div[@id='submenu_electronics' and @class='submenu']//../ul[1]")

@col_linesheet_ref = Element.new(:xpath,
                                 "//table[contains(@id,'channelSubTable')]/thead/tr/th[1]")
@col_linesheet_name = Element.new(:xpath,
                                  "//table[contains(@id,'channelSubTable')]/thead/tr/th[2]")
@col_linesheet_season = Element.new(:xpath,
                                  "//table[contains(@id,'channelSubTable')]/thead/tr/th[3]")
@col_mapping_errs = Element.new(:xpath,
                                    "//table[contains(@id,'channelSubTable')]/thead/tr/th[4]")
@col_new_lines = Element.new(:xpath,
                                "//table[contains(@id,'channelSubTable')]/thead/tr/th[5]")

@link_channel = Link.new(:xpath,"//a[@data-test='menuHeaderChannels']")
@eleh1 = Element.new(:xpath, "//div[@id='page-heading']")
@combo_retailer = ComboBox.new(:xpath, "//select[@id='retailerId']")

@tbl_channels = Element.new(:xpath, "//table[@id='channels-list']")

@tbl_subtable=Element.new(:xpath, "//table//table")
@tbl_subtbl_lines_ref = Element.new(:xpath, "//table//table/tbody/tr/td[1]")
@table_channels = Element.new(:xpath, "//table/tbody/tr/td[2]")
 
@ele_overview = Element.new(:xpath, "//h4[contains(text(), 'Overview')]") 

Tuesday, 7 October 2014

System Details and convert milliseconds to seconds

package pack;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

public class OSDetails {
public static void main(String[] args) throws InterruptedException {
DateFormat dateFormat = new SimpleDateFormat();
Date date = new Date();
System.out.println(dateFormat.format(date).substring(0,7));  
System.out.println("OS Name: "+ System.getProperty("os.name"));
System.out.println("OS Version: "+ System.getProperty("os.version"));
System.out.println("OS Arch: "+ System.getProperty("os.arch"));
System.out.println("Host: "+ System.getProperty("hostname"));
System.out.println("user.home: "+ System.getProperty("user.home"));
System.out.println("user.name: "+ System.getProperty("user.name"));
System.out.println("path.separator: "+ System.getProperty("path.separator"));
System.out.println("user.dir: "+ System.getProperty("user.dir"));
long i1= System.currentTimeMillis();
Thread.sleep(10000);
long i2= System.currentTimeMillis();
System.out.println("Elapsed time in milli seconds: "+ (i2-i1));
System.out.println("Elapsed time in seconds: "+ TimeUnit.MILLISECONDS.toSeconds(i2-i1));
}
}


/* Output:
7/10/14
OS Name: Windows 7
OS Version: 6.1
OS Arch: amd64
Host: null
user.home: C:\Users\IN00739
user.name: IN00739
path.separator: ;
user.dir: C:\Users\IN00739\workspace\RnD
Elapsed time in milli seconds: 10001
Elapsed time in seconds: 10

*/