1

I try catching the html form to fill it out.

Here is the target html source.

<span class="login-id">
  <div id="LoginId">
     <input maxlength="100" name="uji.model.635939.value">
     <input type="hidden" name="uji.model" value="uji.model.635939">
     <input type="hidden" name="uji.model.635939"    value="com.fujitsu.uji.compo.taglib.FieldStringUpdater;vkaiinNinshoID">
  </div>
  <span class="example">(半角英数字)</span>
</span>

I focus on <input maxlength="100" name="uji.model.635939.value"> . And the number 635949 is changed when I connect every time.

And here is my code. I used for to handle multiple cases.

for (int i = 600000; i < 699999; i++)
{
    string s = i.ToString();
    try
    {
        IWebElement id = driver.FindElement(By.Name(String.Format("uji.model.{0}.value", s)));
        id.SendKeys("******@gmail.com");
    }
    catch(OpenQA.Selenium.NoSuchElementException e)
    {
        Console.WriteLine("exception {0}", s);
    }
}

I wonder my code is correct. I'm not sure(By.Name(String.Format("uji.model.{0}.value", s) is correct.

BTW, maxlength="100" is the unique expression in the html source. Is there any way to fill out the form using this? Thank you for reading.

4
  • I think it actually failing that it cant find element is that right? Commented Jan 10, 2017 at 2:51
  • 2
    You can try to use regex to find the number like (?<!\d)\d{6}(?!\d) instead of looping and finding Commented Jan 10, 2017 at 2:51
  • Could you explain me the usage of regex for selenium in more detail? Filling the form is success but it takes long time. Commented Jan 10, 2017 at 3:31
  • why don't you try simple css Selector - driver.FindElement(By.cssSelector("input[name^='uji.model.']")).SendKeys("your_Text"); ? Commented Jan 10, 2017 at 4:48

1 Answer 1

3

Trying to locate the element is an expensive operation. Currently you are doing this up to 100K times, and catch an exception for all the failures, another expensive operation. There also might be numbers not in the specified range.

I suggest you locate the element using its parent element with unique id

driver.FindElement(By.CssSelector("#LoginId > input:nth-child(1)"));

This will give you the first <input> child of <div id="LoginId">

If you don't want to use index, look for an element with value in the name attribute

driver.FindElement(By.CssSelector("#LoginId > input[name*='value']"));
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your help. I need to learn more about CssSelector syntax.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.