How do I find X-Path for elements within a frameset? - html

I'm trying to write a test case for Selenium and I'm having a little trouble finding elements. I believe its because my site uses a HTML frame set.
If I open up Firebug, and try to simply select all links:
//a
... I get no results (although the 'menu' frame contains about 15+ links).
If I right-click in the menu frame and choose to "Show Only This Frame", and then select all links in Firebug, I get all 15+ links returned.
This leads me to believe X-Path cannot iterate through elements within a specific frame. Is that true?
When the site is showing all frames, I can select the specific frame:
//frame[#name='menu']
...but trying to drill down to the links starting with that X-Path does not work:
//frame[#name='menu']//a
//frame[#name='menu']###//a <-- Special '###' syntax I read about somewhere to try.
Any help trying to solve this with X-Paths is appreciated. If a CSS selector will work, I could use some pointers there as well. Thanks!
jg

How about you first select the relevant iframe, and then work with the xpaths within that frame.
Sample code in Ruby
iframename = #driver.execute_script("return document.getElementById('IDName').getElementsByTagName('iframe')[0].getAttribute('Attributename')")
#driver.switch_to.frame iframename
# then work with the xpaths
#driver.find_element(:xpath, "//section[#id='SomeId']/div").click
this should help, unless I got the question wrong.

Related

Find getElementById property in window.document

Summary: I wanted to know if there was a way to open console in chrome, type window, go to document and search for the getElementById method
Reason: I was searching around and found a lot of the CSS styles for an element(see picture 1 below) and was curious if methods like getElementById were displayed as well
What I tried:
1) I tried looking searching for the getElementById by control + f and searched for "get"
2) Tried seeing if I could get info from mdn: https://developer.mozilla.org/en-US/docs/Web/API/Document/Document
3) Tried reading the link pasted on mdn https://dom.spec.whatwg.org/#interface-nonelementparentnode
Still couldn't find it though :/
element css styles
window.document properties
If I understand you right (directly - how to find 'getElementById' property within global Window object) it is possible to do. You should write in the console Window, open document, then __proto__ (should be the last property of the document object), then __proto__ again, and now you can find getElementById method here. The reason is Window object quite difficult, and uses prototypes to keep all inherit properties and methods: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype
you can get all the elements with a defined id doing right click-> inspect element-> console
and then document.querySelectorAll('*[id]')
but based on picture two, you want to retrieve the class name that starts with "google_"
then do document.querySelectorAll('google_');
or can you please clarify the question? maybe I'm not getting it right
You need to console.dir(document.__proto__.__proto__) as it is in the overall prototype of the document

Find HTML span element

HTML screenshotI am trying to build a test case to select an option from the drop down menu but unable to find the element.
I am new to selenium webdriver module I can find elements using xpath and id but unable to find an element from a drop down menu.
I am able to log into the webpage and click "Queues". Now I want to select "All Items" from the queue but gettig errow
All Items
If you are not able to find it by selenium and exception is throwing like element not found that probably there is a frame present and your element is inside it. you need to switch to the frame first.
You can refer my or other answer in below link:
How to select frame if there are multiple frames on a webpage and get content of that frame?
If you are not able to find in HTML then use below code
System.out.println(driver.getPageSource());
It just going to print your HTML, now copy it in notepad++ and search your dropdown Text. now create Xpath

How do I automate tab selection on a website

Here is the website I am trying to access. I dont want the default tab (Day) though, I want to select the Season tab
https://www.eex.com/en/market-data/power/futures/uk-financial-futures#!/2017/05/23
The link appears to be exactly the same whichever tab is chose making differentiation impossible as far as I can tell.
Any help on this would be much appreciated, using whichever programming method and language is appropriate.
Kind Regards
Barry Walsh
The URL does not change since this is an ajax request, which you can see from MarketDataTableAController's getPageData function. You can read about them here https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started
Ive inspected your html and you seem to be using angular. On further inpection you can see that the tabs have ng-click="setActiveTab(tab)" attribute on them. So whenever user clicks, this function gets executed. It is a matter of using this function with the appropriate tab object to get the content to change. You for example could put setActiveTab(tab) into your controller init method since setActiveTab() calls the forementioned getPageData() function to update the page.
Also the tab you are looking for is page.tabs[5] ($parent.page.tabs[5] if referring from TabController) since this is the tab with the label of season. Pass that to setActiveTab() and it should show you the season instead.
However this might not be a good solution since the tab array ordering might change. Then you would need to loop over all objects in page.tabs and see if tab.label === "Season" and pass that in the function instead or better yet use the $filter service provided by angular which would look more cleaner.
Your code source also seems to be minimized and its not very easy to read.

Access 97 VBA writing code

I found that I can write code just by typing everything or activate element, then click for example OnClick property and write code to between the sub-end sub lines.
One person I met said that one has always use mouse and select the property in which you want to write the code, as it might write something else to some files such that the code won't work.
Is this correct or are those two ways to write code equally good? I'm using Access 97.
The short answer is you CAN do it that way. But it doesn't mean you SHOULD.
With a little experimentation I've found that you can type in event subs directly in the code window, and their creation will be reflected in the properties window. This might not have always been the case in older versions of MS Access.
You can also create them by selecting the Control in the code window's top left pull down, and then selecting the event in the top right pull down.
Why would I choose to use the Code Builder (or at least the second option I provided). Because it prevents you from making mistakes. Both in the name of the control/event and in accidentally creating duplicate Subs. Both of which could be frustrating when debugging your application - how long could you spend looking for a bug because you added an extra "S" to an element name by accident. If you follow through from the properties window, you are guaranteed to be working on the right Sub and that it will be spelled correctly.
Note: I've also found that you can delete the entry in the properties window, but it leaves the code behind in the code window. So to make sure it is really gone, you do have to go into the code window and delete the Sub there.
That's not to say that I never do anything directly in the Code window like that - if I've renamed a control, I'll often update the name in the code window. But then I'll go back through the properties window to verify that I've re-connected the subs properly.
"Look, I'm running with scissors!"

Multiselect select element - capturing current option set before adding / removing new items

Hello and thank you for reading.
I have an aspx form hosted in SharePoint 2010 that has some multiple select elements within a form. There are buttons to add and remove options from these select elements.
My problem is that I need to run a query based on the options within these multi select elements each time new options are added / removed from them. SharePoint is executing some server side code I don't have access to but here's my underlying problem.
If I hook into the buttons' onclick event, when my function is called the options have already been added to or removed from the select element. I need to capture the current option set of these elements, before the onclick function executes.
Is there another event I can tie into? Something like onbeforeclick on the buttons or optionsChanged on the multi select element? It doesn't look like any event will satisfy what I need to do here, but I'm hoping someone has faced a similar issue before.
Thanks,
Zachary Carter
The only solution I could come up with is to capture the present set of options each time an option is added or removed.
This solution is going to involve alot of array manipulation however, and if I can avoid that and simply tie into an event, before the onclick event of the button is called, that would be my ideal solution.
This might not be a great answer to your question, and if not, I apologize. However, I just ran into a very similar problem, albeit using Visual Basic. The solution wasn't elegant in my eyes, but I used VB's MouseUp event, which fires when the mouse button is released. On release (i.e., at the end of the previous action), I save all the information in the elements into an array, and then on the next click, before anything else happens, I can check against that array.
Edit: Gah, looks like you posted essentially that solution while I was typing. Sorry I didn't notice.