Reputation: 675
I'm using protractor to test my website and have custom dropdown that open after i click on a button
var list = element(by.xpath('//*[@id="project"]/div[1]/div/div[4]/div[2]/div[1]/button'));
list.click();
and after that i want to click on the 3 item and when I took the xpath of the element I want
var itemtoselect = element(by.xpath('/html/body/ul[2]/li[3]/a'));
and execute the click operation but nothing has happen. how can I fix this issue?
Upvotes: 1
Views: 630
Reputation: 162
The question lacks a little bit of detail, and unfortunately I do not have enough reputation to comment and ask for it.
But Ill try to explain some other ways of accessing that element
Firstly, this issue happened to me on a previous project when opening up a previewed document, and what was happening at least in my case was that there were multiple /html/body
s so I could not reference the second one via a typical xpath.
As a result, I had to locate the element in another fashion.
element.all(by.repeater('SOME LIST NAME')).get(2).click();
The goal: You should find some common aspect that is shared between all the list items whether it be a class, id, partial text, and use that in conjunction with element.all(by.SOMETHING(SOMETHING).get(2).click();
http://timothymartin.azurewebsites.net/protractor-cheat-sheet/
The link above has several examples of alternate ways to find the list item, good luck!
Upvotes: 1