-1

Firefox driver is not entering a value for Firstname field. I'm trying the following:

driver.findElement(By.xpath(//*[@id=\JNHGYHG\"]")).sendsKeys("Hello");

Can someone help me with this?

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
Sitara
  • 1
  • 4

2 Answers2

0

Try this and see any difference.

driver.findElement(By.xpath("//*[@id='JNHGYHG']")).sendKeys("Hello");
JeffC
  • 18,375
  • 5
  • 25
  • 47
KunduK
  • 26,790
  • 2
  • 10
  • 32
  • can you please share html here? – KunduK Feb 08 '19 at 11:51
  • well I cannot share HTML due to privacy. so that's why I asked ho can I run the script with this kind of ID. because I am getting an error message org.openqa.selenium.NoSuchElementException: Unable to locate element: #JNHGYHG – Sitara Feb 08 '19 at 11:58
  • Correct you can share the partial html snapshot only the part it is impacted.Come on that you can do. – KunduK Feb 08 '19 at 12:03
  • driver.findElement(By.id("JNHGYHG")).sendKeys("Hello"); Thread.sleep(2000); – Sitara Feb 08 '19 at 12:20
  • That is not html.I am asking when you inspect the element provide that element html part.Not the java code which you have written. – KunduK Feb 08 '19 at 12:24
  • how to handle dynamic changing elements in XPath? – Sitara Feb 08 '19 at 12:58
0

As mentioned in your code trial there is an error within the Locator Strategy you have used.

Solution

You can use either of the following solutions:

  • Using id attribute:

    driver.findElement(By.id("JNHGYHG")).sendKeys("Hello");
    
  • Using cssSelector:

    driver.findElement(By.cssSelector("#JNHGYHG")).sendKeys("Hello");
    
  • Using xpath (option A):

    driver.findElement(By.xpath("//*[@id='JNHGYHG']")).sendKeys("Hello");
    
  • Using xpath (option B):

    driver.findElement(By.xpath("//*[@id=\"JNHGYHG\"]")).sendKeys("Hello");
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • I tried all above options and getting this message. org.openqa.selenium.WebDriverException: Failed to convert data to an object – Sitara Feb 08 '19 at 11:25
  • Whenever I am running my test case in Firefox I am getting cookies popup I want to remove it how can I do this? We use cookies to make your experience better. To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies. Learn more. – Sitara Feb 08 '19 at 11:48