简体   繁体   English

无法使用Selenium WebDriver定位输入元素

[英]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: 我尝试使用定位器By.ClassNameBy.CssSelector("input[class='text placeholder']")定位它,并尝试:

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: 我将使用dot表示法来匹配ulliinput元素的类:

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 它在iframe中,您需要切换到它
  • 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? 另外,有人可以指出使用Selenium Webdriver解释使用框架的资源吗?

-Amit -阿米特

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Selenium WebDriver 中使用 C# 使用 XPATH 定位动态 Salesforce Lightning INPUT 元素 - How to Locate a DYNAMIC Salesforce Lightning INPUT Element with XPATH using C# in Selenium WebDriver 无法使用 selenium webdriver 单击路径元素 - Not able to click an path element using selenium webdriver Selenium WebDriver:无法找到元素(C#) - Selenium WebDriver: unable to locate element (C#) Selenium WebDriver-无法找到元素异常 - Selenium WebDriver - Unable to locate element exception 如何使用 Webdriver 和 C# 通过 Selenium 定位并单击嵌套在多个框架和框架集中的元素 - How to locate and click on an element which is nested within multiple frame and frameset through Selenium using Webdriver and C# Selenium Chrome 驱动程序无法定位元素 INPUT - Selenium Chrome Driver Unable to locate element INPUT 无法使用C#在Selenium Webdriver脚本中使用XPath定位元素 - Unable to locate an element with XPath in selenium webdriver script with C# 无法使用Selenium WebDriver单击跨度 - Not able to click on span using selenium webdriver 如何使用 Selenium WebDriver 和 C# 在 div 中定位按钮 - How to locate a button inside a div with using Selenium WebDriver and C# 无法使用 ID 在 Selenium 中定位元素。 能够在一页上获取元素。 但是当我在另一个页面上导航时无法定位 - Unable to locate element in Selenium using ID. Able to get the element on one page. However unable to locate when I navigate on another page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM