Error while executing with chrome | Selenium Forum
M
Posted on 10/10/2015
Ashish,
Below code is perfectly working with mozilla, but giving element not visible exception at the line "driver.findElement(By.xpath("//span[@class='nav-action-inner']")).click();" for chrome.
Could you please let me know, how can i execute with chrome?

package framework.testcases.rediff;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

public class SearchProduct{
WebDriver driver=null;
WebDriverWait wait=null;
@Test
public void searchProdTest(){
System.out.println("In createPortfolioTest");
String browser="Mozilla";
if(browser.equals("Mozilla")){
driver=new FirefoxDriver();
}else if(browser.equalsIgnoreCase("Chrome")){
System.setProperty("webdriver.chrome.driver", "C:\\Softwares\\chromedriver.exe");
driver=new ChromeDriver();
}
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://www.amazon.com/");
Actions act=new Actions(driver);
WebElement signIn =driver.findElement(By.xpath("//*[@id='nav-link-yourAccount']/span[1]"));
act.moveToElement(signIn).build().perform();
driver.findElement(By.xpath("//span[@class='nav-action-inner']")).click();
driver.findElement(By.xpath("//*[@id='ap_email']")).sendKeys("madhavi419@gmail.com");
driver.findElement(By.xpath("//*[@id='ap_password']")).sendKeys("weston321");
while(!isElementExists("//*[@id='searchDropdownBox']")){
System.out.println("In side the while");
driver.findElement(By.xpath("//*[@id='signInSubmit']")).click();
pause(5);
}
WebElement searchDropdownBox= driver.findElement(By.xpath("//*[@id='searchDropdownBox']"));
Select searchDropdown= new Select(searchDropdownBox);
searchDropdown.selectByVisibleText("Electronics");
driver.findElement(By.xpath("//*[@id='twotabsearchtextbox']")).sendKeys("iPad");
driver.findElement(By.xpath("//*[@id='twotabsearchtextbox']")).sendKeys(Keys.ENTER);

}
public void pause(int secs){
try {
Thread.sleep(secs*1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public boolean isElementExists(String locatorKey){
int s=driver.findElements(By.xpath(locatorKey)).size();
if(s>0)
return true;
else
return false;
}
}

M
Replied on 12/10/2015

I'm getting org.openqa.selenium.ElementNotVisibleException: element not visible
on both Mozilla and chrome.