Selenium WebDriver Interview Test

Practice tests are very useful for testing the level of our knowledge and skills.

We get useful feedback through them about what we can do with the new learned skills at a certain moment.

But practice tests show us as well what we don't know yet but should know.

What follows is a real interview test for Selenium WebDriver and Java.


1. Open the www.ia.ca in the Chrome browser





2. Click LOANS

3. Click the Mortgages link




4. Click the Calculate Your Payments button




5. Move the Purchase Price Slider to the right

6. Validate that the Purchase Price Slider movement works




7. Change the Purchase Price to 500 000 using the + button of the slider




8. Change the Down Payment to 50 000 using the + button of the slider




9. Select 15 years for Amortization




10. Select Weekly for Payment Frequency




11. Change the Interest Rate to 5%




12. Click the Calculate button




13. Verify that the weekly payments value is 836.75




Good luck doing the exercise!

If you are interested in feedback, post your code in the comments section.





Share this

25 Responses to "Selenium WebDriver Interview Test"

  1. System.setProperty("webdriver.chrome.driver", "D:/Kamaraj/selenium-java-2.52.0/chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("http://www.ia.ca/individuals");
    driver.manage().window().maximize();
    driver.findElement(By.xpath("//*[@id='nav-secondaire']/div[1]/ul/li[4]/a")).click();
    driver.findElement(By.xpath("//*[@id='nav-secondaire']/div[1]/ul/li[4]/ul/li[1]/section/ul/li[1]/a")).click();
    driver.findElement(By.xpath(".//*[@id='main']/div[2]/div[4]/div[1]/div[2]/a")).click();
    for (int i = 0; i < 2; i++){
    driver.findElement(By.xpath(".//*[@id='PrixProprietePlus']")).click();
    }
    for (int i = 0; i < 1; i++){
    driver.findElement(By.xpath(".//*[@id='MiseDeFondPlus']")).click();
    }
    Select oselect = new Select(driver.findElement(By.id("Amortissement")));
    oselect.selectByValue("15");
    Select oselect2 = new Select(driver.findElement(By.id("FrequenceVersement")));
    oselect2.selectByValue("52");
    driver.findElement(By.id("TauxInteret")).clear();
    driver.findElement(By.id("TauxInteret")).sendKeys("5.00");
    Thread.sleep(10000);
    driver.findElement(By.xpath(".//*[@id='btn_calculer']")).click();
    Thread.sleep(10000);
    String value = driver.findElement(By.xpath(".//*[@id='paiement-resultats']")).getText();
    if (value == "$ 836.75") {
    System.out.println("TEXT");}
    else {
    System.out.println("Not TEXT");
    }
    }

    ReplyDelete
    Replies
    1. Hi Kamarajsivam,

      Can you please post the code again and explain where each step of the test case is handled?

      Thanks.

      Alex

      Delete
    2. Hi Kamarajsivam,

      The first 4 suggestions for you are below:

      1. create xpath expressions that are simpler, shorter and do not depend on the position of the element.

      the following expression will not work if the final element is moved around in the page:

      driver.findElement(By.xpath("//*[@id='nav-secondaire']/div[1]/ul/li[4]/ul/li[1]/section/ul/li[1]/a")).click();

      your xpath expression should try to find the final node using the // operator, the element tag and the element attributes.

      2. if the same element is used in multiple actions (clear() and sendKeys()), save the element in a WebElement variable and use the variable.

      this avoids finding the element multiple times:

      driver.findElement(By.id("TauxInteret")).clear();
      driver.findElement(By.id("TauxInteret")).sendKeys("5.00");

      3. use explicit waits instead of driver.findElement() to avoid using delays (thread.sleep(10000)).

      Thread.sleep(10000);
      driver.findElement(By.xpath(".//*[@id='btn_calculer']")).click();

      4. use JUNIT or TEST NG assertions in your test script for making verifications:

      String value = driver.findElement(By.xpath(".//*[@id='paiement-resultats']")).getText();
      if (value == "$ 836.75")
      System.out.println("TEXT");
      else
      System.out.println("Not TEXT");

      Please make these changes and re-submit the code for additional feedback.

      Thanks,

      Alex

      Delete
  2. static WebDriver driver = new ChromeDriver();
    @Test
    public static void cal() throws InterruptedException {

    System.setProperty("webdriver.chrome.driver",
    "D:\\Selenium\\BrowserPlugins\\chromedriver_win32\\chromedriver.exe");

    driver.manage().window().maximize();
    driver.navigate().to("http://www.ia.ca/individuals");
    ExplicitWait("//span[contains(.,'Loans')]");
    driver.findElement(By.xpath("//span[contains(.,'Loans')]")).click();
    driver.findElement(By.xpath("//a[contains(.,'Mortgages')]")).click();
    ExplicitWait("//a[contains(.,'Calculate your payments')]");
    driver.findElement(By.xpath("//a[contains(.,'Calculate your payments')]")).click();

    for (int i = 0; i <2; i++){

    ExplicitWait("//button[contains(@id,'PrixProprietePlus')]");

    driver.findElement(By.xpath("//button[contains(@id,'PrixProprietePlus')]")).click();
    }

    for (int i = 0; i < 1; i++){

    driver.findElement(By.xpath("//button[contains(@id,'MiseDeFondPlus')]")).click();
    }

    WebElement listBox = driver.findElement(By.xpath("//select[@id='']"));
    Select selectvalue = new Select(listBox);
    selectvalue.selectByValue("15");

    WebElement Irate = driver.findElement(By.xpath("//input[contains(@class,'toNumber')]"));
    Irate.clear();
    Irate.sendKeys("5");
    WebElement listBox1 = driver.findElement(By.xpath("//select[contains(@id,'FrequenceVersement')]"));
    Select selectvalue1 = new Select(listBox1);
    selectvalue1.selectByVisibleText("weekly");

    driver.findElement(By.xpath("//button[contains(.,'Calculate')]")).click();
    String value = driver.findElement(By.xpath(".//*[@id='paiement-resultats']")).getText();
    System.out.println(value);
    Assert.assertEquals(value, "$ 836.75");

    }

    public static void ExplicitWait(String text) {
    (new WebDriverWait(driver, 100)).until(ExpectedConditions.elementToBeClickable(By.xpath(text)));
    }

    ReplyDelete
    Replies
    1. Hi Ravi,

      Please see feedback below.

      Thanks,

      Alex

      1. rename ExplicitWait to findElementIfClickable()

      2. replace the next 2 lines

      ExplicitWait("//a[contains(.,'Calculate your payments')]");
      driver.findElement(By.xpath("//a[contains(.,'Calculate your payments')]")).click();

      with

      findElementIfClickable("//a[contains(.,'Calculate your payments')]").click();

      3. use findElementIfClickable() instead of driver.findElement()

      4. save all your xpath expressions in class variables so that they can be used by other class test scripts

      5. do you have to use a static driver variable? does the test script have to be static?

      6. move these 3 lines to the setUp() method:

      System.setProperty("webdriver.chrome.driver",
      "D:\\Selenium\\BrowserPlugins\\chromedriver_win32\\chromedriver.exe");

      driver = new ChromeDriver();

      driver.manage().window().maximize();

      7. do not use xpath expression if the element has id attribute

      Delete
  3. I used property file to store all the xpaths. I did not understand the 2 and 3 rd points . How can I add those two points in to 1. if we do then .click() event will not be present as it's work only for element. Please let me know if i am wrong


    URL=http://www.ia.ca/individuals
    Loans=//span[contains(.,'Loans')]
    Mortgages=//a[contains(.,'Mortgages')]
    Calculateyourpayments=//a[contains(.,'Calculate your payments')]
    Purchaseprice=//button[contains(@id,'PrixProprietePlus')]
    Downpayment=//button[contains(@id,'MiseDeFondPlus')]
    Amortization=//select[contains(@name,'Amortissement')]
    Interestrate=//input[contains(@class,'toNumber')]
    Paymentequency=//select[contains(@id,'FrequenceVersement')]
    Calculate=//button[contains(.,'Calculate')]
    Monthlypayments=.//*[@id='paiement-resultats']

    ReplyDelete
    Replies
    1. Hi Ravi,

      I missed adding to my feedback that you should change the return type of the ExplicitWait() method to WebElement and that you should return the found WebElement object:

      public static WebElement ExplicitWait(String text) {

      WebElement element = (new WebDriverWait(driver, 100)).until(ExpectedConditions.elementToBeClickable(By.xpath(text)));

      return element;
      }

      Hope this helps,

      Alex

      Delete
    2. Thx for your knowledge share :) . Looking more assignments

      Delete
    3. Hi Ravi,

      You are welcome.

      We are not done here :)

      Upload the changed code for more feedback.

      Thanks,

      Alex

      Delete
  4. Alex mailed the latest code to alex@alexsiminiuc.com . Please check and let me know comments . Whenever I pasted the code and refresh posted code is not displaying so, I mailed

    ReplyDelete
    Replies
    1. Hi Ravi,

      this is your code.

      I will provide feedback shortly.

      thanks.

      Alex

      URL=http://www.ia.ca/individuals
      Loans=//span[contains(.,'Loans')]
      Mortgages=//a[contains(.,'Mortgages')]
      Calculateyourpayments=//a[contains(.,'Calculate your payments')]
      Purchaseprice=//button[contains(@id,'PrixProprietePlus')]
      Downpayment=//button[contains(@id,'MiseDeFondPlus')]
      Amortization=//select[contains(@name,'Amortissement')]
      AmortizationValue=15 years
      Interestrate=//input[contains(@class,'toNumber')]
      InterestrateValue=5
      Paymentequency=//select[contains(@id,'FrequenceVersement')]
      PaymentequencyValue=weekly
      Calculate=//button[contains(.,'Calculate')]
      Monthlypayments=.//*[@id='paiement-resultats']


      static WebDriver driver;

      static Properties properties = new Properties();
      static FileInputStream inputproperties = null;

      @Test
      public void setup() throws IOException
      {

      driver = new ChromeDriver();
      System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\BrowserPlugins\\chromedriver_win32\\chromedriver.exe");

      inputproperties = new FileInputStream("D:\\Selenium\\Frame\\Dummy\\Properties\\config.properties");

      properties.load(inputproperties);
      driver.manage().window().maximize();
      driver.navigate().to(properties.getProperty("URL"));

      }

      @Test(dependsOnMethods={"setup"})
      public void cal() throws InterruptedException {
      findElementIfClickable(properties.getProperty("Loans")).click();
      findElementIfClickable(properties.getProperty("Mortgages")).click();
      findElementIfClickable(properties.getProperty("Calculateyourpayments")).click();

      for (int i = 0; i <2; i++){
      findElementIfClickable(properties.getProperty("Purchaseprice")).click();

      }

      for (int i = 0; i < 1; i++){
      findElementIfClickable(properties.getProperty("Downpayment")).click();

      }

      selectValueFromListBox(properties.getProperty("Amortization"),properties.getProperty("AmortizationValue"));

      enterTextboxValue(properties.getProperty("Interestrate"),properties.getProperty("InterestrateValue"));

      selectValueFromListBox(properties.getProperty("Paymentequency"),properties.getProperty("PaymentequencyValue"));

      findElementIfClickable(properties.getProperty("Calculate")).click();

      String value = driver.findElement(By.xpath(properties.getProperty("Monthlypayments"))).getText();

      System.out.println(value);
      Assert.assertEquals(value, "$ 836.75");

      }

      public static WebElement findElementIfClickable(String text) {

      WebElement element = (new WebDriverWait(driver, 200)).until(ExpectedConditions.elementToBeClickable(By.xpath(text)));

      return element;

      }

      public static void selectValueFromListBox(String listbox, String inputValue)
      {

      try {

      Thread.sleep(8000);
      WebElement listBox = driver.findElement(By.xpath(listbox));
      Select selectvalue = new Select(listBox);
      selectvalue.selectByVisibleText(inputValue);

      } catch (Exception e) {

      throw new RuntimeException("Exception while procesing selectValueFromListBox: ", e);

      }
      }

      public static void enterTextboxValue(String textBox, String inputValue) {

      try {

      driver.findElement(By.xpath(textBox)).click();
      driver.findElement(By.xpath(textBox)).clear();
      driver.findElement(By.xpath(textBox)).sendKeys(inputValue);

      } catch (Exception e) {

      throw new RuntimeException("Exception while procesing enterTextboxValue: ", e);

      }
      }

      Delete
  5. if you upload your code and it does not show up on the page, feel free to email it to me at alex@alexsiminiuc.com.

    i will upload it for you.

    ReplyDelete
  6. CODE POSTED BY RIYAN:

    Riyan has left a new comment on your post "Selenium WebDriver Interview Test":

    public class MortgagePaymentCalculator {
    WebDriver driver;

    @Before
    public void SelectBrowser(){

    //1. Open the www.ia.ca in the Chrome browser
    String browserName = System.getenv("browser");
    if(browserName != null && browserName.equalsIgnoreCase("chrome")){
    driver = new ChromeDriver();
    }
    else{
    driver =new FirefoxDriver();
    }
    driver.get("http://www.ia.ca");
    driver.manage().window().maximize();

    }

    @Test
    public void MortgageCalculate() throws InterruptedException{

    //1. Click LOANS
    WebDriverWait wait = new WebDriverWait(driver,20);
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(text(), 'Loans')]")));

    WebElement loanLink = driver.findElement(By.xpath("//span[contains(text(), 'Loans')]"));

    loanLink.click();

    //2. Click the Mortgages link

    WebElement mortgagesLink = driver.findElement(By.xpath("//a[contains(text(),
    'Mortgages')]"));

    mortgagesLink.click();

    //3. Click the Calculate Your Payments button

    WebElement calculateButton = driver.findElement(By.xpath(".//*[@id='main']/div[2]/div[4]/div[1]/div[2]/a"));

    calculateButton.click();

    //6. Move the Purchase Price Slider to the right

    WebElement purchaseSlider = driver.findElement(By.xpath(".//*[@id='form_calculateur_versements']/div[2]/div/div[2]/div/div[1]/div[9]"));

    WebElement to = driver.findElement(By.xpath("//*[@id='form_calculateur_versements']/div[2]/div/div[2]/div/div[1]/div[3]"));

    Actions builder = new Actions(driver);
    Action dragAndDrop = builder.clickAndHold(purchaseSlider)
    .moveToElement(to)
    .release(to)
    .build();

    dragAndDrop.perform();

    //7. Validate that the Purchase Price Slider movement works

    boolean moved = false;

    if(purchaseSlider != null){
    moved = true;
    }
    System.out.println(moved);
    Assert.assertTrue(moved, "Price Slider movement works");

    //8. Change the Purchase Price to 500 000 using the + button of the slider
    WebElement minusButton= driver.findElement(By.id("PrixProprieteMinus"));

    for(int i=0;i<5;i++){
    minusButton.click();
    }

    WebElement plusButton = driver.findElement(By.id("PrixProprietePlus"));

    for(int i=0;i<2;i++){

    plusButton.click();

    }

    //9. Change the Down Payment to 50 000 using the + button of the slider

    WebElement downPayment = driver.findElement(By.xpath(".//*[@id='MiseDeFondPlus']"));

    downPayment.click();

    //10. Select 15 years for Amortization

    Select select = new Select(driver.findElement(By.xpath(".//*[@id='Amortissement']")));

    select.selectByVisibleText("15 years");;
    //11. Select Weekly for Payment Frequency

    Select select1 = new Select(driver.findElement(By.xpath(".//*[@id='FrequenceVersement']")));

    select1.selectByVisibleText("weekly");;
    //12. Change the Interest Rate to 5%

    WebElement interestRate = driver.findElement(By.xpath(".//*[@id='TauxInteret']"));

    interestRate.clear();

    interestRate.sendKeys("5");

    //13. Click the Calculate button
    WebElement calculate = driver.findElement(By.xpath(".//*[@id='btn_calculer']"));

    calculate.click();

    Thread.sleep(3000);

    //14. Verify that the weekly payments value is 836.75

    WebElement paymentValue = driver.findElement(By.xpath(".//*[@id='paiement-resultats']"));

    String result = paymentValue.getText();

    Assert.assertEquals(result, "$ 836.75", "Test passed");

    }

    @After
    public void TearDown(){

    driver.quit();

    }

    }

    ReplyDelete
    Replies
    1. Hi Riyan,

      Please see below the first feedback for you.

      Thanks.

      Alex

      1. the purpose of the method that uses the @Before annotation is to prepare the test environment needed by the test scripts;

      calling this method selectBrowser() is incorrect as many other things may need to be done in this method

      a better name than selectBrowser() is needed such as setUp() or prepareEnvironment();


      2. you can declare the WebDriverWait as a class member and instantiate it (wait = new WebDriverWait(driver,20);) in the setUp() method.


      3. the driver.get("http://www.ia.ca") command should not be in the setUp() method (using the @Before annotation) as it is possible that
      some of the test scripts do not start on the home page


      4. this explicit wait returns a web element:

      wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(text(), 'Loans')]")));

      an explicit wait of this type can be used instead of driver.findElement() as it has the advantage that it waits for the element until the element is
      available.


      5. this xpath expression is not optimal:

      ".//*[@id='main']/div[2]/div[4]/div[1]/div[2]/a"

      you should build xpath expressions that use the tag and attributes of the element to be found


      6. save all xpath expressions as class members

      Delete
  7. Replies
    1. this feedback applies to the last version of your code.

      1. both TestNg and JUNIT have @Before annotation for setting up the test
      environment.

      If you use the @Before annotation for the setUp() method, this annotation of the test script does not need the DependsOnMethods() part:

      @Test(dependsOnMethods={"setup"})

      2. navigating to the first page should be done in the test script instead of the setUp() method:

      driver.navigate().to(properties.getProperty("URL"));

      this is because the test class may have test scripts that start with a different page

      3. the names of your methods are not clear at all.

      the name of any method should be short, descriptive and clear.

      public void cal() is none of those.

      something like testCalculatePayments() is better.

      the same can be said about

      selectValueFromListBox - selectValue() is sufficient as you cannot make selections for other html elements

      enterTextboxValue - text box is the only element where you can type a value; how about type() as a name?

      4. use the findElementIfClickable() not only in the test script but in all methods

      Change the code based on this feedback and then add comments about where each step of the test case is implemented.

      Thanks.

      Alex

      Delete
    2. Ravi's latest code (April 4)

      public class mortgagePaymentCalculator {

      //initialization of driver with properties file.

      static WebDriver driver;
      static Properties properties = new Properties();
      static FileInputStream inputproperties = null;

      // setup method to initialize the browser type and loading the propertiy file
      @BeforeMethod
      public void setup() throws IOException
      {

      driver = new ChromeDriver();
      System.setProperty("webdriver.chrome.driver",
      "D:\\Selenium\\BrowserPlugins\\chromedriver_win32\\chromedriver.exe");

      inputproperties = new FileInputStream("D:\\Selenium\\Frame\\Dummy\\Properties\\config.properties");
      properties.load(inputproperties);

      }

      @Test
      public void calculatePayments() throws InterruptedException {

      driver.manage().window().maximize();

      //Navigating to the www.ia.ca, here URL value will be loaded from Property file
      driver.navigate().to(properties.getProperty("URL"));

      //Click the Loans link
      findElementIfClickable(properties.getProperty("Loans")).click();

      //Click the Mortgages link
      findElementIfClickable(properties.getProperty("Mortgages")).click();

      // Click the Calculate Your Payments button
      findElementIfClickable(properties.getProperty("Calculateyourpayments")).click();

      // Change the Purchase Price to 500 000 using the + button of the slide
      for (int i = 0; i <2; i++){
      findElementIfClickable(properties.getProperty("Purchaseprice")).click();
      }

      // Change the Downpayment to 50 000 using the + button of the slide
      for (int i = 0; i < 1; i++){
      findElementIfClickable(properties.getProperty("Downpayment")).click();
      }

      // Selecting the Amortization from list of values
      selectValue(properties.getProperty("Amortization"),properties.getProperty("AmortizationValue"));

      //Entering the Interestrate
      enterValue(properties.getProperty("Interestrate"),properties.getProperty("InterestrateValue"));

      // Selecting the Paymentequency from list of values
      selectValue(properties.getProperty("Paymentequency"),properties.getProperty("PaymentequencyValue"));

      // Click the Calculate button
      findElementIfClickable(properties.getProperty("Calculate")).click();

      // Verify that the weekly payments value is 836.75 as extracting the value
      String value = driver.findElement(By.xpath(properties.getProperty("Monthlypayments"))).getText();

      System.out.println(value);

      // Verifying the actuval value and derived value both are same
      Assert.assertEquals(value, "$ 836.75" , "Test Passes");

      }

      // This methos us used to wait the driver until driver found the element
      public static WebElement findElementIfClickable(String text) {

      WebElement element = (new WebDriverWait(driver, 200)).until(ExpectedConditions.elementToBeClickable(By.xpath(text)));

      return element;
      }

      //This methos is used to select the value from drop down list
      public static void selectValue(String listbox, String inputValue) {

      try {
      Thread.sleep(8000);
      WebElement listBox = driver.findElement(By.xpath(listbox));
      Select selectvalue = new Select(listBox);
      selectvalue.selectByVisibleText(inputValue);

      } catch (Exception e) {
      throw new RuntimeException("Exception while procesing selectValueFromListBox: ", e);
      }
      }

      //This methos is used to enter the value to a text box
      public static void enterValue(String textBox, String inputValue) {

      try {
      driver.findElement(By.xpath(textBox)).click();
      driver.findElement(By.xpath(textBox)).clear();
      driver.findElement(By.xpath(textBox)).sendKeys(inputValue);
      } catch (Exception e) {
      throw new RuntimeException("Exception while procesing enterTextboxValue: ", e);
      }
      }

      Delete
  8. Replies
    1. more feedback

      1. need a tearDown() method with the @AfterMethod annotation for closing the driver

      2. driver.manage().window().maximize() can be in the setUp() method;
      this way, if you have multiple scripts, there is no need to repeating this line in each script

      3.i dont see code for these 2 steps of the test case:

      Move the Purchase Price Slider to the right
      Validate that the Purchase Price Slider movement works

      The purchase price slider needs to be moved by dragging and dropping.

      4. no need of a for statement for just 2 repetitions:

      for (int i = 0; i <2; i++){
      findElementIfClickable(properties.getProperty("Purchaseprice")).click();
      }

      5. no need of a for statement here:

      for (int i = 0; i < 1; i++){
      findElementIfClickable(properties.getProperty("Downpayment")).click();
      }

      6. use explicit waits (findElementIfClickable) in the selectValue and typeValue() methods

      7. the code is using properties.getProperty() for reading locators, urls, values;
      it would be more readable if you would have something like getLocator(), getValue(), getUrl()

      8. you should validate that each step of the test script worked
      example:

      findElementIfClickable(properties.getProperty("Purchaseprice")).click();
      findElementIfClickable(properties.getProperty("Purchaseprice")).click();

      after changing the purchase price by clicking the + button twice, you should validate that the displayed purchase price is indeed correct (500 000)

      Delete
  9. Thank u for your information. I read your shared information on selnium Topic.
    Selenium Online Training

    ReplyDelete
  10. Replies
    1. your code did not get uploaded so here it is:

      class selenium_interview_test(unittest.TestCase):

      def test_selenium_interview_test(self):
      try:
      self.driver = webdriver.Firefox()
      self.driver.get("http://ia.ca/individuals")
      wait = WebDriverWait(self.driver, 50)
      self.driver.maximize_window()
      wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "navbar-sub-main")))
      self.driver.find_element_by_link_text("LOANS").click()
      wait.until(EC.visibility_of_element_located((By.LINK_TEXT,"Mortgages")))
      self.driver.find_element_by_link_text("Mortgages").click()
      wait.until(EC.element_to_be_clickable((By.LINK_TEXT,"Calculate your payments")))
      # Calculate Your Payments button
      self.driver.find_element_by_link_text("Calculate your payments").click()

      #Verifying the element to be clickable
      wait.until(EC.element_to_be_clickable((By.ID,"PrixProprietePlus")))
      # Move the Purchase Price Slider to the right
      source1 = self.driver.find_element_by_class_name('slider-track-high')
      action = ActionChains(self.driver)
      print source1.location
      action.drag_and_drop_by_offset(source1,787,629).perform()
      time.sleep(10)
      # Change the Purchase Price to 500 000 using the + button of the slider
      source2 = self.driver.find_element_by_class_name('slider-horizontal')
      action = ActionChains(self.driver)
      print source1.location
      action.drag_and_drop_by_offset(source2,0,0).perform()
      assert "500 000" in self.driver.find_element_by_xpath("/html/body/div[3]/div[2]/div[7]/div/div[1]/div[1]/form/div[2]/div/div[2]/div/div[5]/div[3]").text
      wait.until(EC.element_to_be_clickable((By.ID,"MiseDeFondPlus")))

      #Change the Down Payment to 50 000 using the + button of the slider
      self.driver.find_element_by_id("MiseDeFondPlus").click();
      #Select 15 years for Amortization
      wait.until(EC.visibility_of_element_located((By.NAME,"Amortissement")))
      select = Select(self.driver.find_element_by_name('Amortissement'))
      select.select_by_visible_text("15 years")
      #Select Weekly for Payment Frequency
      wait.until(EC.visibility_of_element_located((By.NAME,"FrequenceVersement")))
      select = Select(self.driver.find_element_by_name('FrequenceVersement'))
      select.select_by_visible_text("weekly")
      #Change the Interest Rate to 5% by clearing the previous value and enering new value
      wait.until(EC.visibility_of_element_located((By.ID,"TauxInteret")))
      self.driver.find_element_by_id("TauxInteret").clear()
      self.driver.find_element_by_id("TauxInteret").send_keys("5.00")
      #Click the Calculate button
      self.driver.find_element_by_id("btn_calculer").click()
      #asserting the calculate value whther is valid or not
      assert "$ 836.75" in wait.until(EC.visibility_of_element_located((By.ID,"paiement-resultats"))).text
      self.driver.close()
      except Exception, e:
      print e
      self.driver.quit()
      raise

      suite = unittest.TestLoader().loadTestsFromTestCase(selenium_interview_test)
      unittest.TextTestRunner(verbosity=2).run(suite)

      Delete
    2. 1. I dont see setUp() and tearDown() methods


      2. wait.until(EC.visibility_of_element_located((By.LINK_TEXT,"Mortgages")))
      self.driver.find_element_by_link_text("Mortgages").click()

      These lines are redundant as any explicit wait returns a web element.

      You can save the result of the wait.until to a webelement variable and then click it.


      3. time.sleep(10)

      Try avoiding any driver.findElement() statements and time.sleep(10) in your code.

      Replace both of these with explicit waits.

      See the Beginners Guide To Explicit Waits article from my blog.


      4. The test script should not include any webdriver methods.

      Use the page objects model for this purpose.

      Google "page objects model" and read Martin Fowler's article for more details.

      Delete
    3. this xpath expression is not good:
      "/html/body/div[3]/div[2]/div[7]/div/div[1]/div[1]/form/div[2]/div/div[2]/div/div[5]/div[3]

      read the XPATH locators cheat sheet from my blog.

      Delete
  11. This comment has been removed by the author.

    ReplyDelete