RE: Facing Issue when trying to select country code from drop down in Yahoo Sign up Page.

I am trying to select the country code from the county code drop down but Its throwing element not visible Exception. Below is the code I have created to Signup.
Please help me!

Code:

package WebDriverBasics;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class YahooSignUp {

public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub

WebDriver driver= new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get(“https://edit.europe.yahoo.com/”);
driver.findElement(By.id(“login-signup”)).click();
driver.findElement(By.id(“first-name”)).clear();
driver.findElement(By.id(“first-name”)).sendKeys(“Shailu”);
driver.findElement(By.id(“last-name”)).clear();
driver.findElement(By.id(“last-name”)).sendKeys(“Bijal”);
driver.findElement(By.id(“user-name”)).clear();
driver.findElement(By.id(“user-name”)).sendKeys(“shailubijal”);
driver.findElement(By.id(“password”)).clear();
driver.findElement(By.id(“password”)).sendKeys(“12345678876543”);
//  driver.findElement(By.id(“female”)).click();

List<WebElement> rbutton=driver.findElements(By.name(“gender”));
boolean result=rbutton.get(0).isSelected();
if(result==true)
{
rbutton.get(1).click();
}
else

rbutton.get(0).click();

new Select(driver.findElement(By.id(“month”))).selectByVisibleText(“November”);
new Select(driver.findElement(By.id(“day”))).selectByVisibleText(“12”);
new Select(driver.findElement(By.id(“year”))).selectByVisibleText(“2008”);
driver.findElement(By.id(“mobile”)).clear();
driver.findElement(By.id(“mobile”)).sendKeys(“1234524242”);

driver.findElement(By.cssSelector(“span.country-code-arrow”)).click();
//   driver.findElement(By.cssSelector(“#yui_3_7_3_2_1458635314439_1047>a”)).click();
Select pselect=new Select(driver.findElement(By.id(“country-codes-menu-1”)));
//  pselect.selectByVisibleText(“Uruguay (+598)”);
Thread.sleep(5000);

List<WebElement> osize=pselect.getOptions();
int listsize=osize.size();
for(int i=0;i<listsize;i++)
{
System.out.println(pselect.getOptions().get(i).getText());
}
Thread.sleep(5000);
pselect.selectByIndex(3);

driver.findElement(By.cssSelector(“#selected-country-code-2 > a > span.country-code-arrow-container > span.country-code-arrow”)).click();
new Select(driver.findElement(By.id(“country-code-rec”))).selectByVisibleText(“United Kingdom (+44)”);

driver.findElement(By.id(“relationship”)).clear();
driver.findElement(By.id(“relationship”)).sendKeys(“frnd”);
driver.findElement(By.id(“mobile-rec”)).clear();
driver.findElement(By.id(“mobile-rec”)).sendKeys(“132131”);

driver.findElement(By.xpath(“//input[@value=’Create account’]”)).click();

}

}

Shailu9759 Default Asked on March 22, 2016 in Selenium WebDriver.
Add Comment
2 Answers

use sendKeys method to pass a county code instead of click operation if it fails try to use selectText

Train Answered on March 22, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.