0
votes

I am unable to write on this popup message using selenium. Please feel free to help me in this case. My Code is:-

public static void main(String[] args) 
{
System.setProperty("webdriver.gecko.driver", "F:\\gecko_driver\\geckodriver-
v0.16.1-win64\\geckodriver.exe");
WebDriver driver= new FirefoxDriver();
driver.get("https://www.heycare.com");   

driver.findElement(By.xpath("html/body/div[2]/header/div/nav/div/a")).click();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
System.out.println("hello world-----1");
driver.switchTo().frame(0);
driver.findElement(By.id("mobile")).sendKeys("7015273543");
System.out.println("hello world-----2");
//Driver.findElement(By.id("mobile")).sendKeys("7015273543");
driver.findElement(By.id("Pass")).sendKeys("123456");
}

Error:- Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: *[name='mobile']

Code is working fine till:- driver.findElement(By.xpath("html/body/div[2]/header/div/nav/div/a")).click(); Unable to write on that popup form that comes after clicking on the login button..

1

1 Answers

0
votes

I navigated to that website and successfully targetted the mobile number field using this css selector #mobile which targets the id attribute. You're doing this for your password field. Try having your test use this:

Driver.findElement(By.id("mobile")).sendKeys("7015273543");

See if that helps...

Edit: I'm not sure that the unformatted code block you're showing that switches frames is necessary. Unless you're working with iframes, I didn't see any in the minute I was looking around.

Edit2:

WebDriver driver = new FirefoxDriver();
driver.get("https://www.heycare.com");
System.out.println("hello world");

driver.findElement(By.className("log-pop")).click(); 

WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(By.name("mobile")));

driver.findElement(By.name("mobile")).sendKeys("7015273543");
driver.findElement(By.id("Pass")).sendKeys("123456");

You could try something like this, I added in a call to WebDriverWait to account for the possible delay between clicking the login button, and waiting for the login prompt popup to finish it's animation prior to be allowed to be clicked. I'm not sure if this will work in your case, but it's a possibility I sniffed out when I was observing the site's behavior. (I didn't test any of this code, it's freehand written. So take it with a grain of salt. It might not work flawlessly as is.

Bit of java nit, you should make your object references lowercase, save capitalized symbols for class names. I had a moment of trying to figure out why you were calling static methods of a class called Driver instead of an instance of the class WebDriver