I am trying to do registration for this site
Registration page is inside a popup page.
HTML Code:
<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");
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");
When I execute above code, I have got an error like element not visible
Can anyone help me on this issue?
Ajax popup on way2automation site is a tricky one because if you look for the username field by name
By.name("username")
, you will end up with 2 elements - one for username from signup popup, one from singin popup. To avoid this you have to explicity mention the correct element. This can be done via the following code:As you can see in the code I am using
class
of the login popup -.ajaxlogin
. I have usedJava
, but the concept is the same - you have to refer to theusername
element via css selector with popup class included:By.cssSelector(".ajaxlogin input[name='username']")
Try this below code using xpath locator
Explanation of xpath:- Use
name
attribute of<input>
tag.Suggesstion:- Instead of using
absolute xpath
, userelative xpath
.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
The problem is that there are two username INPUT fields. The way I typically handle this is to find a parent of the element that I want that has an ID or something unique that will distinguish the two elements. In this case, you can use a simple CSS selector,
Note the
load_box
ID that distinguishes the two INPUTs.that site has 2 forms with the id load_form so you're getting the first one which isn't visible since it's the login form. You want the second one which is the register form.
you can use a selector to grab one of the fields that exists on the registration page and then move up to it's parent form and get all descendants that are fieldsets to fill out.
Here is the
xpath
you can use to pass the text "Dev" into the field labelled with "Name".driver.findElement(By.xpath("//div[@class='fancybox-overlay fancybox-overlay-fixed']//form[@id='load_form']/fieldset/input[@name='name']")).sendKeys("Dev");
Let me know if this answers your question.
Use below xpath: