0

I've been working on a project using selenium 2 webdriver.

Took me a while but finally got it working inside iframes of a web page.

Thing is, I searched a lot and seen many examples but none that looked like what I ended up with, looks a bit weird and hacky.

My question is if anyone who uses selenium can see a better and cleaner way of doing this.

namespace mySeleniumChrome
{
    class Program
    {

        static void Main(string[] args)
        {
            String pathtodriverfolder = @"path to selenium chromedriver.exe";

            ChromeDriverService driverService = ChromeDriverService.CreateDefaultService(pathtodriverfolder);
            driverService.HideCommandPromptWindow = true;

            ChromeOptions options = new ChromeOptions();
            options.AddArguments("test-type");

            IWebDriver driver = new ChromeDriver(driverService, options);

                        driver.Navigate().GoToUrl("http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe");

            IWebDriver frame = driver.SwitchTo().Frame("view");
            //frame.SwitchTo().Frame(0);

            IWebElement frame2 = frame.FindElement(By.TagName("iframe"));

            frame.SwitchTo().Frame(frame2);

            IWebElement searchbox = frame.FindElement(By.Id("gsc-i-id1"));

            searchbox.SendKeys("testing");

            frame.Dispose();
            driver.Dispose();

        }
    }
}

Just looking for some advice or pointers.

Thank you for taking the time to read.

Edited by Suzie999

1
Contributor
0
Replies
16
Views
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.