3

When I run the following program it runs absolutely fine, until I get to filling out the form on the webclip section. Once it gets there it says the id "txtTemplateName" can't be found. I copied and pasted that name directly from Inspecting the element. It isn't that i'm not giving it enough time to load either, I've given it a full 5 seconds in the past just to make sure, and still nothing.

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System.Diagnostics;
using System.Linq;

namespace Build1Evan
{
class Program
{
    static void Main(string[] args)
    {

        IWebDriver driver1 = new FirefoxDriver();   
        driver1.Navigate().GoToUrl("URL");

        Process.Start(@FILE"); // This is just an Auto IT Script to get me by a login window

        bool loginCheck1 = driver1.FindElements(By.Id("btnLoginAgain")).Count() > 0;
        if (loginCheck1 == true)
        {
            driver1.FindElement(By.Id("btnLoginAgain")).Click();
        }

        System.Threading.Thread.Sleep(500);
        driver1.FindElement(By.LinkText("Configuration")).Click();
        System.Threading.Thread.Sleep(500);                             
        driver1.FindElement(By.LinkText("Payloads")).Click();
        System.Threading.Thread.Sleep(500);
        driver1.FindElement(By.PartialLinkText("WebClip")).Click();
                // BELOW IS WHERE I ENCOUNTER THE ISSUE 
        System.Threading.Thread.Sleep(500);
        driver1.FindElement(By.Id("txtTemplateName")).SendKeys("TESTING");
    }
}
}

I also encounter the error when I try selecting any other element in the form, rather it be a button or another text field.

EDIT: PHOTO AS ASKED

EDIT 2: PHOTO 2 Also just a FYI i have had no problems using Selenium IDE, it is easily able to select the element and fill it in.

Evan
  • 37
  • 6

2 Answers2

2

According to your screenshot, I think your app embed the form by using <object id="panelcontentobject" data="....

In case the form is really inside object tag, you have to create a WebElement of the object tag then use JavaScriptExecutor to retrieve attribute or interact with the form. For example,

IWebElement objectTag= driver.FindElement(By.Id("panelcontentobject"));
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("return (arguments[0].contentDocument.getElementById('txtTemplateName')).click()",objectTag);

Please see Examples from http://aksahu.blogspot.com/2015/05/dealing-with-object-tags-in-selenium-webdriver.html?m=1

Buaban
  • 5,029
  • 1
  • 17
  • 33
  • sorry for taking so long to get back check my most recent edit. – Evan Jan 18 '16 at 14:26
  • Thank you for you're response! I just realized i can access the objects directly from a different URL and am going to work forward from there. – Evan Jan 19 '16 at 19:32
1

The form is probably inside iframe, you need to switch to it before you can perform actions on elements inside it:

IWebElement frame = driver.FindElement(By.Id(frameId));
driver.SwitchTo().Frame(frame);

You can also use explicit wait to make sure the element you want is visible and you can interact with it:

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementIsVisible(By.Id("txtTemplateName"))).SendKeys("TESTING");
Guy
  • 46,488
  • 10
  • 44
  • 88