1

I am automating one application using selenium in which I am stuck at a point where I am not able to find the way to locate an element for same fields which are in different blocks but their xpaths and all other entities are same hence I am unable to locate element for fields of the second block.

There are 2 blocks which are having same fields (Street text field, State drop down, city text field an zip text field). I have done the code for the first block using XPath and it is working fine.

But the problem is with the second block where all the fields are the same and their xpaths are also same. When I execute the script what is happening is, data entered in the first block is done correctly, but for the second block, as the xpaths are same the control is going back to the first block and start entering data in already filled fields. Nothing is there for differentiating so I can not locate the elements for the second block.

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
Tester
  • 21
  • 3
  • The two blocks that you are using, are they appears in different windows or different pop-ups? If so, use some delay time after completing first block automation. Hope this will help you. – Gautam Bothra May 16 '18 at 09:38
  • Two blocks are present on the same pop up. Its a detailed information form and divided into multiple blocks like first is of Basic Information, next one is of company information like that. And I stuck on 'company address' block which present on the same page. – Tester May 16 '18 at 09:48
  • If you are using the same xpath for locating an element, it will always get the first matching element. Thus the overwriting off the first element values. Use findElements, the plural version which returns a list and then use index. Else use index on the xpath query. Also add the relevant html – Grasshopper May 16 '18 at 09:48
  • Nothing is there for differentiating , it is not a good way to say things. Provide the HTML for two blocks. – cruisepandey May 16 '18 at 09:50

2 Answers2

1

if you have multiple blocks in that, You can apply as below example:-

("//select[@class='form-control']")[1]
Gautam Bothra
  • 565
  • 1
  • 8
  • 23
0

What i understood from the question is that "different blocks" mentioned in the question is in the same page.If my understanding is correct, you can try with FindElements method and then can use get method for accessing the required webelement . e.g if Webdriver instance is driver

List<WebElement> StreetTxtList=driver.findElements("//mention your locator here");
StreettxtList.get("//mention the index").click();

you can also add wait accordingly if required

APa
  • 18
  • 1
  • 6