Question Selenium WebDriver Filling a form

Anonymous

Well-known member
Joined
Sep 29, 2020
Messages
94
Programming Experience
Beginner
I using the following form to fill values from a C# Desktop application . I able to fill first Name, Last Name, and email address but I am getting an element not found exception for the drop down and the text area.


My Code :
C#:
 private void button1_Click(object sender, EventArgs e)
        {
            
            // Initialize Chrome WebDriver
            IWebDriver driver = new ChromeDriver();

            // Navigate to the form URL
            driver.Navigate().GoToUrl("https://formsmarts.com/html-form-example");

            var frame = driver.FindElement(By.CssSelector("iframe.fs_embed"));
            driver.SwitchTo().Frame(frame);
            driver.FindElement(By.CssSelector("input[placeholder='Your first name']")).SendKeys("John");
            driver.FindElement(By.CssSelector("input[placeholder='Your last name']")).SendKeys("Doe");
            driver.FindElement(By.CssSelector("input[placeholder='Your email address']")).SendKeys("johndoe@example.com");
          
            SelectElement selectElement = new SelectElement(driver.FindElement(By.Id("u_k0J_338367")));
            selectElement.SelectByValue("Website Feedback");

            driver.FindElement(By.CssSelector("input[placeholder='Your comment']")).SendKeys("Everything Rocks!!!");

Find Element by Id is not working for any element but I was not sure what else to use for the dropdown as placeholder is not present for it. But The placeholder attribute is present for text area still I am getting the exception.
 
It's not clear why this is a C# question. Sounds more like a HTML and/or Selenium issue.

What exception are you getting?

There is more than one way to get references to elements using Selenium than just using IDs. For example, you can use relative paths, just like CSS uses relative paths.

Why are you trying to drive the website UI using Selenium? Ask the website owner for an API for you to call directly. They will appreciate it since it will decrease the CPU/RAM/bandwidth loads on their system be deceasing the number of requests.
 
Last edited:
Back
Top Bottom