Hi folks,
Is there any way to find div tag element by its attribute "onclick"?
eg.
<div class="hotzoneDiv" id="hotzoneDiv_main" onclick="install();">
How to find element by "onClick"
Re: How to find element by "onClick"
Hi,
Could you please be more specific about what exactly you want to achieve?
If you mean to use the "onclick" attribute in xpath, then yes, you can do that. It can be used as any other attribute. So the xpath could look like this...
Just one important note. The "onclick" attribute is a dynamic one, which means the page/application must be loaded at a time of recording/tracking the elements or even fiddling with the path weight editor. If the page is not loaded/active, dynamic attributes are not visible in spy and so they cannot be recorded or tracked!
If you want the "onclick" attribute to be automatically added to the xpath while recording/tracking the element, then you need to change the xpath weights to give the onclick attribute higher priority over ID or any other attribute with higher priority. By default, onclick attribute "weight" is 0 and ID attribute is 200. So you need to set the onclick weight value at least 201, to give it priority over ID. Hope this helps?
Could you please be more specific about what exactly you want to achieve?
If you mean to use the "onclick" attribute in xpath, then yes, you can do that. It can be used as any other attribute. So the xpath could look like this...
Code: Select all
/body/div[@id='hotzoneDiv_main' and @onclick='install();']
If you want the "onclick" attribute to be automatically added to the xpath while recording/tracking the element, then you need to change the xpath weights to give the onclick attribute higher priority over ID or any other attribute with higher priority. By default, onclick attribute "weight" is 0 and ID attribute is 200. So you need to set the onclick weight value at least 201, to give it priority over ID. Hope this helps?
You do not have the required permissions to view the files attached to this post.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration