Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
uptightkid
Posts : 4
Join date : 2012-12-03

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

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;
}
}
}
avatar
uptightkid
Posts : 4
Join date : 2012-12-03

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

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;
}
}
}
avatar
iosman
Posts : 4
Join date : 2013-02-18

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

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
Sponsored content

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

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