0

I have been trying for days to select this button... I've tried xpaths by ID type, input type, child of, etc. What am I missing here, why is VS unable to locate the "element" ? I can use the same command to ID and click a radio button on something such as FB or another site... (Bear with me, I'm newish to automation and making an attempt at self-teaching)

Message: OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"xpath","selector":".//input[@id='q1_1']"} (Session info: chrome=80.0.3987.87)

  //radio button, if I can actually get this to work....
        driver.FindElement(By.XPath(".//input[@id='q1_1']")).Click();

enter image description here

1

The xpath that you currently have will look for element with tag input and id q1_1 from the current node.

driver.FindElement(By.XPath(".//input[@id='q1_1']")).Click()

So , if you have executed some scripts and the current focus is on any tag after the input tag , then

".//input[@id='q1_1']" 

will not return any element .

So instead of

".//input[@id='q1_1']" 

Use:

"//input[@id='q1_1']"  // removed the dot at the starting

The above locator will look for input tag with the specified Id , starting from the root , unlike your case where it searched only from the current node.

| improve this answer | |
  • I felt like I already attempted this way (Had to reboot so lost all my undos) But I tried again with the update. Same result "Message: OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"xpath","selector":"//input[@id='q1_1']"}" – user43500 Feb 6 at 20:31
  • @user43500 add explicit wait and check whether the element is in iframe – PDHide Feb 6 at 21:29
  • removing the dot(.) should work. If not try to implement WebDriverWait. – Updesh Kumar Feb 7 at 13:50
  • Could you share the webpage URL? – Kenil Fadia Feb 17 at 11:21
0

Please go through a Select class, it should work

 // Select By Class
  Select Radiobutton = new Select(driver.findElement(By.id("q1_1")));
  Radiobutton.selectByValue("1");
  Radiobutton.selectByIndex(1);
  Thread.sleep(3000);

Please go through type attribute, it also works

`(By.cssSelector("input[type='radio']")).click();

| improve this answer | |
  • No luck still, whatever method I try, the radio button does not get selected and I get the return "Message: OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: " followed by the whatever action was used to attempt to locate the button. – user43500 Feb 7 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.