Search
 
 

Display results as :
 


Rechercher Advanced Search

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Getting value in element - result not the same as on screen

View previous topic View next topic Go down

Getting value in element - result not the same as on screen

Post by uptightkid on Sun Feb 17, 2013 8:06 am

Hi,

I have a Java Webdriver script designed to enter values in a website and to extract the answers generated.

My problem is that the Webdriver script finds the answers on the webpage but not all the answers/results that Webdriver finds are the same as the on screen result.

The expected result and what is shown on the page is as follows...
Total = $118.67
postal is $86.57
cover is $32.10

The actual that Webdriver returns is...
Total = $118.67
postal is $50.80
cover is $14.05

I cannot figure out why Webdriver is returning a result which is different from what I can see how on screen.

I have included my script, the website is open to the public so you can run the script yourself.

I am using Webdriver 2.29
========================================================

import java.io.IOException;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;

public class AusPostFireFox{
private WebDriver driver;

private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://www.google.com.au/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

// Setting browser type and versions, not working, need to investigate

// DesiredCapabilities browser = DesiredCapabilities.firefox();
// browser.setVersion("17");
}

@Test
public void testPost1() throws Exception {

// Selemium driver posts HTTP command get for Australia Post URL
driver.get("http://auspost.com.au/apps/international-letter.html");

// Fill out and Submit form using hard coded data, refactored to new method
fillform();

// Waiting for 10 second for website to calculate price
for (int second = 0;; second++) {
if (second >= 10) fail("timeout");
try { if (driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*New calculation[\\s\\S]*$")) break; } catch (Exception e) {}
Thread.sleep(1000);
}

takeScreenShot();


getWebsitePrices();

}

public void getWebsitePrices() {
// Getting Prices from website, printing prices to console



String X = driver.findElement(By.cssSelector("tfoot > tr > td.price")).getText();
System.out.println("Total = " + X);




String xpathPostal = driver.findElement(By.xpath("(//form[@id='intLetterForm']/div[2]/table/tbody/tr[2]/td[2])")).getText();
System.out.println("postal is " + xpathPostal);


String xpathCover = driver.findElement(By.xpath("(//form[@id='intLetterForm']/div[2]/table/tbody/tr[3]/td[2])")).getText();
System.out.println("cover is " + xpathCover);
}

public void takeScreenShot() throws IOException {

// Getting Screenshot of summary page and price
// File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

// Saving screen shot locally, Java syntax requires the double back slashs in all file paths
// FileUtils.copyFile(scrFile, new File("C:\\Selenium Stuff\\Screenshots\\screenshot.png"));
}

private void fillform() {


// NB..research converting xpaths to properties to avoid hardcoding of locators

// driver.findElement(By.linkText("RESET")).click();
driver.findElement(By.id("searchCriteria.countryCode")).click();

// Why is the new command on the next line esential?
driver.get("http://auspost.com.au/apps/international-letter.html");
driver.findElement(By.id("searchCriteria.countryCode")).click();
new Select(driver.findElement(By.id("searchCriteria.countryCode"))).selectByVisibleText("IRELAND");
driver.findElement(By.id("radWeight1")).click();
driver.findElement(By.xpath("//*[@id='intLetterForm']/div[2]/div/button")).click();
driver.findElement(By.id("searchCriteria.serviceTypeCode1")).click();
driver.findElement(By.id("searchCriteria.optionsMap['INTL_SERVICE_ECI_PLATINUM']1")).click();
driver.findElement(By.id("searchCriteria.extraCoverMap[INTL_SERVICE_ECI_PLATINUM]")).click();
driver.findElement(By.id("searchCriteria.extraCoverMap[INTL_SERVICE_ECI_PLATINUM]")).clear();
driver.findElement(By.id("searchCriteria.extraCoverMap[INTL_SERVICE_ECI_PLATINUM]")).sendKeys("1000");

driver.findElement(By.xpath("//*[@id='intLetterForm']/div[5]/div/button")).click();
}

@After
public void tearDown() throws Exception {
// driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}

private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}

uptightkid

Posts : 4
Join date : 2012-12-03

Back to top Go down

Re: Getting value in element - result not the same as on screen

Post by uptightkid on Sun Feb 17, 2013 8:14 am

Opps...sorry guys, I forgot to declare the base url in my last script, here is the correct script.

========================================================


import java.io.File;
import java.io.IOException;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;

public class AusPostFireFox{
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://www.google.com.au/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

// Setting browser type and versions, not working, need to investigate

// DesiredCapabilities browser = DesiredCapabilities.firefox();
// browser.setVersion("17");
}

@Test
public void testPost1() throws Exception {

// Selemium driver posts HTTP command get for Australia Post URL
driver.get("http://auspost.com.au/apps/international-letter.html");

// Fill out and Submit form using hard coded data, refactored to new method
fillform();

// Waiting for 10 second for website to calculate price
for (int second = 0;; second++) {
if (second >= 10) fail("timeout");
try { if (driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*New calculation[\\s\\S]*$")) break; } catch (Exception e) {}
Thread.sleep(1000);
}

takeScreenShot();


getWebsitePrices();

}

public void getWebsitePrices() {
// Getting Prices from website, printing prices to console



String X = driver.findElement(By.cssSelector("tfoot > tr > td.price")).getText();
System.out.println("Total = " + X);




String xpathPostal = driver.findElement(By.xpath("(//form[@id='intLetterForm']/div[2]/table/tbody/tr[2]/td[2])")).getText();
System.out.println("postal is " + xpathPostal);


String xpathCover = driver.findElement(By.xpath("(//form[@id='intLetterForm']/div[2]/table/tbody/tr[3]/td[2])")).getText();
System.out.println("cover is " + xpathCover);
}

public void takeScreenShot() throws IOException {

// Getting Screenshot of summary page and price
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

// Saving screen shot locally, Java syntax requires the double back slashs in all file paths
FileUtils.copyFile(scrFile, new File("C:\\Selenium Stuff\\Screenshots\\screenshot.png"));
}

private void fillform() {


// NB..research converting xpaths to properties to avoid hardcoding of locators

// driver.findElement(By.linkText("RESET")).click();
driver.findElement(By.id("searchCriteria.countryCode")).click();

// Why is the new command on the next line esential?
driver.get("http://auspost.com.au/apps/international-letter.html");
driver.findElement(By.id("searchCriteria.countryCode")).click();
new Select(driver.findElement(By.id("searchCriteria.countryCode"))).selectByVisibleText("IRELAND");
driver.findElement(By.id("radWeight1")).click();
driver.findElement(By.xpath("//*[@id='intLetterForm']/div[2]/div/button")).click();
driver.findElement(By.id("searchCriteria.serviceTypeCode1")).click();
driver.findElement(By.id("searchCriteria.optionsMap['INTL_SERVICE_ECI_PLATINUM']1")).click();
driver.findElement(By.id("searchCriteria.extraCoverMap[INTL_SERVICE_ECI_PLATINUM]")).click();
driver.findElement(By.id("searchCriteria.extraCoverMap[INTL_SERVICE_ECI_PLATINUM]")).clear();
driver.findElement(By.id("searchCriteria.extraCoverMap[INTL_SERVICE_ECI_PLATINUM]")).sendKeys("1000");

driver.findElement(By.xpath("//*[@id='intLetterForm']/div[5]/div/button")).click();
}

@After
public void tearDown() throws Exception {
// driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}

private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}

uptightkid

Posts : 4
Join date : 2012-12-03

Back to top Go down

Re: Getting value in element - result not the same as on screen

Post by iosman on Tue Feb 19, 2013 4:33 am

I'm looking for an automation tester (Selenium Web Driver) with solid experience in Java. Please contact me if you are interested.
toptestlondon at googlemail dot com

iosman

Posts : 4
Join date : 2013-02-18

Back to top Go down

Re: Getting value in element - result not the same as on screen

Post by Sponsored content Today at 3:19 am


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum