I absolutely cannot get this xpath to work... selecting a radio button



  • 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



  • 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.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2