last day (16 days later) » 

4:24 PM
0
A: Clicking on Image Link with Selenium webdriver java

Xwris StoixeiaIt looks your xpath is wrong. Personally I would start from the div and the drill down to the actual < a > tag. In some cases where your web-element sits under a < li > tag, I would go even further up the tree and select a div which is not hidden. i.e you instruct it to search for under the sp...

 
thanks, will try this xpath as well. Please review the comments on earlier answer. It seems like it is finding the image.
 
Seen them, that's logical if the http link is attached to an image itself. Grabbing the <a> tag will gurantee you are grabbing the actual http link you want to visit
 
tried all three suggestions above. Same error. However, the attributes are returning all blank.
 
Try to remember xPath as following: //<name_of_element>[@name_of_attribute='value_of_attribute'] Another tip. In fact you can locate an element (if it is unique) without even specifying a value. So if the a tag is the only one inside your div in your example this should work as well: //div[@class='x-tree-node-item']//a[@id] Please notice how I'm not specifying a value for id (because you mentioned it is changing!). If there are no more < a > tags the above will locate the element as well..
I can see some <li> elements below, if there are some above this could be the case. If it is possible please share with us the page so you get a definite answer. Otherwise please attach more of the html code (upwards is where we are interested). Alternatively I will highly recommend to install xpath helper for Chrome. This is a small add one which helps you try your xpaths. When successful it will highlight the element so you are 100% sure. If there are >1 matches for your xpath (so more element than 1) then xpath Helper will show this in brackets (3)--> 3 elements with the same xpath
Note: if you are able to locate your element using my xpath and xpathHelper for Chrome confirms it then you have some error in the way you are locating the element.
 
Unfortunately, this is a locked down machine. Can't install anything on this one. However, after staring at the code for sometime, I see that the <img> tag is not closed in html. Shouldn't it have a /> or </img> before the </a> is closed?
 
4:24 PM
Correct and correct. Both <a> and <img> should be closed with the respective tags as you mentioned. I can see the </a> tag but not the </img> - is it possible that all of this is generated dynamically on the go? Key question is, are there any li elements on top of the div? So is the //div[@class='x-tree-node-item'] enclosed into a <li> ?
Another question is, are you trying to click on 'Manage Users' so another submenu will show up?
 
Is this dynamically generated -- Yes. Will Manage users open another sub-menu -- Yes. Is the Div enclosed in <li> element -- No. There are bunch of <div> elements which constitute menu.
 
Okay thanks for your swift reply. Check my updated answer with the image and try going one div higher on each attempt. Best of luck! :)
 
The image doesn't show up on your answer :)
And I am using Internet Explorer and using "Inspect Element" for that link. My mistake, actually there is an image closing tag. I must have omitted it by mistake during copy and paste.
 
No worries. Are you able to hit f12 and kinda manually locate the image?
 
Yes, I am able to manual locate the image in browser
 
4:27 PM
Meaning hitting F12 and going //div and so on?
 
let me try that
 
cool np
if you are able to locate it in this way then there is definitely something wrong with your webelement wait command. If that is the case, check my answer here for a clean wait.

https://stackoverflow.com/questions/43529097/not-waiting-so-long-for-an-element/43529286#43529286
 
So, when I hit F12, we get the inspect element panel. There is a find there
when I put in xpath in find, it can't find the image
 
ok
Forget for 1 minute your page and try the same on stackoverflow on your question. Can you locate the title by using the following xpath
bear with me
//div[@id='question-header']//h1//a[text()[contains(.,'Image')]]
so the above xpath should locate your question's title on SO
I just wanted to give you one working example, so you see that it works! :)
 
undefined
 
4:37 PM
By the way, why my image does not show? If I refresh it shows
 
I am sure I am putting this xpath in incorrect place
I am putting it in console command line
 
wrong
 
in the Find box, it works
 
Should be under the 'Elements' tab, please try iregfreshing the SO questuion
my image should appear! :)
 
It can find the <div>
 
4:39 PM
cool
can you do something similar then for your website?
 
so, let me try your xpath on our page
 
np take your time
 
//a[text()[contains(.,'age User')]]
doesn't give any results. Find box turns red :)
 
with the div in front perferrably
because that might be too 'deep'
so
//div[@class='x-tree-node-item']//a[text()[contains(.,'Manage Users')]]
or
//div[@class='x-tree-node-item']//a[@title='Manage Users']
the only logical explanation I can think of is the need to start the divs from higher up. So start from the first div which enclose all divs. I just finished work and I'm going home by train. Will check again at 20:00 UK time to see how you 've done sohail, best of luck!
 
thanks
 
 
1 hour later…
6:01 PM
The problem was finally solved. The markup had duplicate items with same title. Only one of them was displayed at one time. Thanks
 

  last day (16 days later) »