1

I am new to selenium and trying to find the correct xpath or CSS for the html code below and after spending so much time and after numerous trials I was not able to click on these elements and I need some help here. There seems to something very basic that I am missing here.I am getting NoSuchElementException.

The 1st HTML:

<input class="form-control" id="name" name="name" value="" type="text">

I tried following code:

driver.findElement(By.xpath("//*[@id="name"]")).sendKeys("Something");
driver.findElement(By.id("name")).sendKeys("Something");
driver.findElement(By.cssSelector("input[value='']")).sendKeys("Something");

The 2nd HTML:

<a href="#fragment2" data-toggle="tab" aria-expanded="true">
   <span>Module Permissions</span>
</a>

I tried following code:

driver.findElement(By.xpath("//span[contains(text(), 'Module Permissions')]")).click();
driver.findElement(By.linkText("Module Permissions")).click();

My Test Env:

  1. Google Chrome Version 66.0.3359.181
  2. Selenium WebDriver Version: 3.12

Any help is much appreciated.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
AmKu
  • 23
  • 4
  • 1
    are you in an iframe? – Simon N May 25 '18 at 01:50
  • 1
    search is` there any tag: `frame` or iframe` in the whole page HTML? If so you need to use switch to the frame where the element resides at first. – yong May 25 '18 at 01:55
  • Yes, I was actuallly in an iframe. Once I switched to the iframe i was able to click on the element. Thanks for your suggestion. – AmKu May 26 '18 at 02:23

1 Answers1

0
  1. It seems you got an error before sending keys. Is that only the code ? only input tag? if that is the case then try this.

    driver.findElement(By.cssSelector("input")).sendKeys("Something");
    
  2. Try this.

    driver.findElement(By.cssSelector("a")).click();
    

much better if you provide the link of the page or whole html of the page

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352