1

element is not found //HTML Code

<input type="text" maxlength="61" style="width:185px;" value="" name="name73652d80" onblur="fieldTrack(this);
"/>

input type="text" onblur="fieldTrack(this);" onfocus="javascript:checkFullName(document.forms[0].name73652d80.value);" onclick="javascript:UncheckAllOptions();" maxlength="30" style="width:185px;" value="" name="login73652d80"/>
<br/>

// My Selenium code

driver.findElement(By.xpath("//input[contains(@type,'text')][starts-with(@name,'name')]")).sendKeys("Mahesh");

The above code execute successfully but the below code are fail I did some permutation with contains and starts-with method but its not working

driver.findElement(By.xpath("//input[starts-with(@type,'text')][contains(@name,'login')])]")).sendKeys("maheshwagh27");
1
  • Did you check second input is not a tag. So may be this is issue from UI side.
    – Sagar007
    May 11, 2016 at 7:32

3 Answers 3

3

Here is change that I have made in your code-

are they 2 different textboxes or single one? If you add screenshot of your textboxes it will clear to all of us-

WebElement nameTbox= driver.findElement(By.xpath("//input[starts-with(@type,'text')][contains(@name,'name73652d80')])]"));
nameTbox.sendKeys("maheshwagh27");
1

Solution 1 :

You are putting extra brackets for this. So remove it:

//input[starts-with(@type,'text')][contains(@name,'login')]

Solution 2 :

You have to use conditions for xpath.

//input[starts-with(@type,'text') and contains(@name,'login')]

Please let me know If any query.

0
0

Did you try looking at the second xpath in firepath?

It is a possibility that with the second xpath there are more than one element present on the screen and that's why your webdriver is not able to find the xpath.

I guess the first one will be failing and the second should be passing because you are using @name, 'name' in first but the @name,'login' in second. So the second should be correct.

1
  • Hi, I did both but still my code is fail
    – Mahesh
    May 10, 2016 at 13:54

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.