Selenium Automation无法在Way2Automation网站上输入用户名 [英] Selenium Automation unable to enter username in Way2Automation website
问题描述
我正在尝试为此网站
注册页面在弹出页面内部.
Registration page is inside a popup page.
HTML代码:
<fieldset>
<label>Username:</label>
<input name="username" required="" type="text"/>
</fieldset>
当我尝试使用下面的尝试代码查找元素时,找不到元素.
When I try to find the element using below tried code, element is not getting find.
driver.FindElement(By.XPath(".//*[@id='load_form']/fieldset[1]/input")).SendKeys("Kal");
我也使用CssSelector进行了尝试,但是面临相同的问题.
I have also tried this with using CssSelector, but facing the same issue.
driver.FindElement(By.CssSelector("div#load_box form#load_form input[name=username]")).SendKeys("kal");
执行上述代码时,出现类似element not visible
When I execute above code, I have got an error like element not visible
有人可以在这个问题上帮助我吗?
Can anyone help me on this issue?
推荐答案
使用 xpath定位器
driver.FindElement(By.XPath("//input[@name='name']")).SendKeys("Kal");
xpath的解释:-使用<input>
标签的name
属性.
建议:-代替使用absolute xpath
,而使用relative xpath
.
注意:-:在到达此Web元素之前,请等待几秒钟,以便您的驱动程序可以找到该Web元素.因此,您不会收到类似element not visible
Note:- Before reach to this web-element provide some few seconds of wait, so your driver may able to find the web-element. So, you will not get an error like element not visible
这篇关于Selenium Automation无法在Way2Automation网站上输入用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!