Issue
Need some help.
I am trying to Log into Flipkart and buy the first Iphone via selenium.
However, I am getting stuck in the below mentioned page
https://www.flipkart.com/apple-iphone-6…/p/itmen2yynt6bz3gg…
I tried to click on the Compare Checkbox, 16GB Button, Buy Now button and Add to cart Button , but all of the operations are giving unable to locate error.
Any help will be greatly appreciated.
Thanks in Advance
I have used Implicit wait as well as Expected Wait but neither wait.
I also check for iframes in the page, but that did not work either.
@Test(priority = 3,enabled = true)
public void inPage() throws InterruptedException {
WebDriverWait wait = new WebDriverWait(driver, 100);
wait.until(ExpectedConditions.elementToBeClickable(By.className("_2AkmmA _2Npkh4 _2kuvG8 _7UHT_c"))).click();
}
PASSED: logIn
PASSED: search
FAILED: inPage
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.className: _2AkmmA _2Npkh4 _2kuvG8 _7UHT_c (tried for 100 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:95)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:272)
at First.inPage(First.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at
Solution
I've observed that clicking on the first search result (first iPhone) is opening up a new tab, in that case you have to switch to the new tab and perform the further actions.
driver.get(
"https://www.flipkart.com/search?q=iphone&sid=tyy%2C4io&as=on&as-show=on&otracker=AS_QueryStore_OrganicAutoSuggest_0_4&otracker1=AS_QueryStore_OrganicAutoSuggest_0_4&as-pos=0&as-type=RECENT&as-backfill=on");
By firstSearchResult = By.className("_3O0U0u");
driver.findElement(firstSearchResult).click();
Thread.sleep(1000);
String currentWindow = driver.getWindowHandle();
Set<String> windows = driver.getWindowHandles();
for (String window : windows) {
if (!window.equals(currentWindow)) {
driver.switchTo().window(window);
}
}
// I'm performing these three steps to set pin-code, as i'm not logging-in. You
// may not have to perform these three steps as you are already logged -in.
driver.findElement(By.id("pincodeInputId")).clear();
driver.findElement(By.id("pincodeInputId")).sendKeys("500081");
driver.findElement(By.xpath("//*[@class='_2aK_gu' and text()[contains(.,'Check')]]")).click();
By button = By.xpath("//button[text()[contains(.,'BUY NOW')]]");
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(button));
driver.findElement(button).click();
Answered By - Appu Mistri
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.