Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
625k views
by Contributing Tester (22 points)
Hi,

I have follow the checkout process with website http://automationpractice.com/index.php. These are the below steps i have followed:

(1) Access the webste: http://automationpractice.com/index.php

(2) Add any item in cart

(3) Click to checkout button. After clicking this checkout button, Getting the error message like "Unable to locate element in application". I have used different combination of xpath for the checkout proceed button. These are like below:

//element= driver.findElement(By.id("//*[@id=\"layer_cart\"]/div[1]/div[2]/div[4]/a/span"));

//element= driver.findElement(By.id("//*[contains(@title,'Proceed to checkout')]"));

//element= driver.findElement(By.id("//*[@title='Proceed to checkout']"));

element= driver.findElement(By.id("//*[@class='btn btn-default button button-medium']"));

No Attachment tab is there. Please advice me that how can i share the document.

1 Answer

0 like 0 dislike
by The go-to Tester (142 points)

Your code will surely fail because, you are supplying  XPath but, you are trying to identify values by id.

Your code should like,

element= driver.findElement(By.xpath("//*[@id=\"layer_cart\"]/div[1]/div[2]/div[4]/a/span"));

Try that and let us know.
by Contributing Tester (22 points)
Hi Sandeep,  
Thanks for your quick response. Added xpath instead id in my command but now getting error like element not visible in console. Please advice me.

Regards
Samta
by The go-to Tester (142 points)
Yes, because, the command is executed even before an element appears on the screen.

You can use explicit wait to wait for an elemnet to appear.

E.g.
WebDriverWait wait=new WebDriverWait(driver, 20); //this will wait for an element to appear within 20 minutes

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"layer_cart\"]/div[1]/div[2]/div[4]/a/span")));

element= driver.findElement(By.xpath("//*[@id=\"layer_cart\"]/div[1]/div[2]/div[4]/a/span"));
by Contributing Tester (22 points)
Hi Sandeep,

Thank you so much for your support. Sorry for late reply.

Now it is working after using explicit wait to locate the element in application by selenium webdriver. I have used your code and working fine. Just one query, I have used POM to generate framework and given every locator in java function . The xpath(//*[@id=\"layer_cart\"]/div[1]/div[2]/div[4]/a/span) of object stored in function Checkout_Page1. Please see below function.  

public static WebElement Checkout_Page1(ChromeDriver driver) {   
        element= driver.findElement(By.xpath("//*[@id=\"layer_cart\"]/div[1]/div[2]/div[4]/a/span"));
        return element;
    }

If i call this function in wait until condition,  then it gives error like"The method xpath(String) in the type By is not applicable for the arguments (WebElement)".
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath((Checkout_Process_Page.Checkout_Page1(driver)))));

If i used direct like below then it is working.
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(("//*[@id=\"layer_cart\"]/div[1]/div[2]/div[4]/a/span"))));

Please let me know.
by Contributing Tester (22 points)
Hi Sandeep,

 I am getting the error message like"he method xpath(String) in the type By is not applicable for the arguments (WebElement)". what i understand is i can not pass webelement in wait.until stement, It should be string not webelement.

Regards
Samta
by Master (1.2k points)
Hi Samta,

This is a new question altogether.

Kindly post it as a new question.

Mayur
by Contributing Tester (22 points)
Hi Mayur,

Thanks for your suggestion and raised different question.

Previously you people were supporting online support also. Did you stop online support?

Please let me know

Regards
Samta
by Master (1.2k points)
That was just to help you, if you face any difficulties in using the q&a site.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...