1

I am automating a webpage using Selenium Webdriver. I am not able to click a button a modal pop up window using simple element locator method.

Example:

  • open www.walmart.com
  • enter tv in the search box.
  • select some tv and click "Add to Cart"
  • Now a pop up window comes where "Checkout" button is located. I need to click on this "checkout" button.

I tried switchTo() windowhandle, I tried switchTo() frame but nothing worked.

halfer
  • 19,824
  • 17
  • 99
  • 186
nname
  • 59
  • 1
  • 9
  • You should show some work at least. It's against SO policy to ask this kind of help without showing any work from your side – Saifur Sep 20 '15 at 23:45
  • ok. code i wrote to click on checkout web elementdriver.findElement(By.xpath(".//*[@id='PACCheckoutBtn']")).click(); – nname Sep 20 '15 at 23:47
  • when i inspect the window it shows – nname Sep 20 '15 at 23:52
  • @Nidhi Please use the edit link under your question to provide more information rather than putting it in the comments. – Dijkgraaf Sep 21 '15 at 00:30

1 Answers1

1

This website is very slow and has loading issue. So, I suggest you to use Explicit wait for each findElement. I have written the following script and works perfectly

WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();        

driver.get("http://www.walmart.com/");
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("[placeholder='Search']")))
        .sendKeys("TV");
driver.findElement(By.cssSelector(".searchbar-submit.js-searchbar-submit")).click();
wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("#tile-container>div>a>img")))
        .get(0).click();        
wait.until(ExpectedConditions.elementToBeClickable(By.id("WMItemAddToCartBtn"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("PACCheckoutBtn"))).click();
Saifur
  • 16,081
  • 6
  • 49
  • 73
  • awesomeeeeeeeeee....... it worked :D . Thanks soooo much Saifur. so basically it is the timing issue... when I was using plain driver.findElement(By.xpath(".//*[@id='PACCheckoutBtn']")).click(); it did not work. But when I just changed the line to include wait, it worked. I just changed my line to WebDriverWait wait = new WebDriverWait(driver, 20); wait.until(ExpectedConditions.elementToBeClickable(By.id("PACCheckoutBtn"))).click(); – nname Sep 21 '15 at 00:21
  • Yes, it is timing issue. Glad to help – Saifur Sep 21 '15 at 00:22