简体   繁体   中英

Not able to locate input element using Selenium WebDriver

I am new to Selenium. In a specific scenario I am not able to catch an input element. below is the code:

<ul class = "form1">
    <li class="firstName">
        <input placeholdervalue="First name" tabindex="1" placeholder="First name" class="text" placeholdevalue="First name" data-input-rule="name" data-value-rule="required" maxlength="20" type="text">
    </li>
</ul>

I want to locate input element. I tried locating it using locator By.ClassName , By.CssSelector("input[class='text placeholder']") and also tried:

wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("input[className='text' and placeholdevalue='First name'"))).SendKeys("Vipul");

but input element is not getting selected. Please let me know the right way to select input element.

I would use a dot notation to match the classes of ul , li and input elements:

By.CssSelector("ul.form1 li.firstName input.text")

If the element still cannot be found, then there could two most commonly met reasons:

  • it is inside an iframe and you need to switch to it
  • you need to wait for the element to appear

I'll expand these items in case you would still have problems finding the element.

Thanks for the reply.

It worked with this,

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("ul.form1 li.firstName input.text"))).SendKeys("Vipul"); 

Is this the right way of using wait?

Also, can anybody point out to resources which explain working with frames using selenium webdriver?

-Amit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM