Tuesday 7 January 2014

Difference between Absolute path & Relative path

Difference between Absolute path & Relative path.

Absolute path will start with root path (/) and Relative path will from current path (//)
Click Here for Detailed Answer
Absolute xPath : /html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div[@id='main']/div[@id='Blog1']/div[1]/div[1]/div/div[1]/div/h3/a

Relative xPath : //h3/a[text()='Working on New Window']

Or In  Selenium IDE.
http://ruchi-myseleniumblog.blogspot.in
and
http://ruchi-myseleniumblog.blogspot.in/2013/12/100-selenium-interview-questions.html
Both are absolute path.

Let say you have set you base URL as
http://ruchi-myseleniumblog.blogspot.in
and you want to go to other page of it like
http://ruchi-myseleniumblog.blogspot.in/2013/12/100-selenium-interview-questions.html
or
http://ruchi-myseleniumblog.blogspot.in/2013/12/basic-core-java-interview-questions.html

then you don’t have to type complete absolute path each time. use relative path like
/2013/12/100-selenium-interview-questions.html.
Or
/2013/12/basic-core-java-interview-questions.html

Once you set the base URL you don’t have to pass the same URL for any of the page on that webpage.
First set the base URL in SIDE as
http://ruchi-myseleniumblog.blogspot.in then run script.


15 comments:

  1. Nice explanation Ruchi... Great job

    ReplyDelete
  2. I am using intern testing tool with an application developed in dojo 1.8 (using custom template widgets). The page loads successfully in the webdriver but intern is not able to identify the HTML elements and throws timeout error. waitForElementByCssSelector, waitForVisibleById or elementById give timeout error.
    please help

    ReplyDelete
  3. I am using intern testing tool with an application developed in dojo 1.8 (using custom template widgets). The page loads successfully in the webdriver but intern is not able to identify the HTML elements and throws timeout error. waitForElementByCssSelector, waitForVisibleById or elementById give timeout error.

    ReplyDelete
  4. HI Ruchi, Hope you doing good,

    If possible can you please post in detail about the Xpath.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. @Sapna
    use WebDriverWait to resolve this issue.

    ReplyDelete
  7. package Package;
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.testng.annotations.*;

    public class Openbrowser {

    @Test
    public void method() throws Exception
    {
    WebDriver driver=new FirefoxDriver();
    String relpath="https://www.google.co.in/";
    String abspath="/imghp?hl=en&tab=wi&ei=omUhVPCQJ8PjuQSUvICgBw&ved=0CAQQqi4oAg";
    driver.get(relpath);
    driver.get(abspath);
    driver.manage().timeouts().implicitlyWait(400, TimeUnit.SECONDS);
    //driver.close();
    System.out.println("Test");
    //driver.quit();

    }
    }

    I have tried but i could not be able to navigate to relative path.Please suggest....

    ReplyDelete
  8. Nice job... Thanks

    ReplyDelete
  9. @nagarjunakrishna illuri:

    You have confused yourself a bit. You took the seedURL as relpath and the relativePath as abspath. Also, you are unable to get to your relpath because you immediately initialized your driver to abspath, which according to your string initialization, cannot exist on its own. You need to do the following:

    String absolutePath = relpath + abspath;
    driver.get(absolutePath);

    ReplyDelete
  10. Nice blog thanks
    Can you send me framework link my maild jessica102214@gmail.com

    ReplyDelete
  11. Hello, I would like to subscribe for this webpage to get newest updates,
    so where can i do it please help.

    ReplyDelete