Capturing variable xpath in selenium IDE - variables

Am trying to capture a element (delete button in gmail) which has variable xpath.
The xpath is something like this-
//*[#id=':rr']/div/div[4]/div[1]/div[1]/div[1]/div/div/div[2]/div[3]
can somebody kindly help?

No, this is where the IDE falls behind and it's for good reason. It, along with other 'XPath-ified' (e.g using the 'XPath' right-click option in Firebug) tools will only take a guess at where something is located in the DOM.
In that, I mean it's going to walk down the tree and see where it is, in relation to the other elements, i.e it'll walk down one set of tr elements, and know there are 7 of them, therefore it'll know that the first one can be accessed using [1], then the next one can be accessed using [2] etc etc...
It doesn't, or really can't, know what is unique enough for you to use. That's why it's down to you to figure it out.
As for Gmail specifically, I would suggest you either fall back to Gmail's basic mode - so the markup will be easier to deal with or stop completely and use a particular set of API's in whatever language you are using to deal direct with the mailboxes in that account.
Though, if you do this, you'll need to dump the IDE altogether - essentially this is beyond the IDE and is a logical thing you need to decide yourself. The IDE is not designed for this.
Though, a tip would be see what's near the delete button. Is there a static element, that has the same attributes all the time, near it? You can get that element, and walk through to the DOM to your 'delete button'.

Related

Can I use Selenium IDE and have it use XPath instead of ID by default?

I have a situation where the IDs of all elements are unique GUIDs, regenerated on each page load.
So I can't use IDs, although Selenium IDE defaults to IDs for obvious reasons.
My workaround is to record with Selenium IDE, then go back and manually edit the IDs to replace them with the right XPath, but this is really time-consuming.
Is there a way it can be set to use XPaths instead of IDs, by default?
Or is there another similar application/extension which can do this?
Selenium IDE/Katalon... recordings can be an OK starting point, depending on who you ask, but you need to go over them.
XPath expressions are specially tricky and often need to be worked on after a recording tool obtains them.
There is no way around this even if you can get the tool you are using to use xpath by default somehow.

In chrome dev tools what is the combination of these attributes called and why can i not just do a quick copy of them

I don't see anything in the right-click menu that will give me this. I always have to write it manually
Are you asking about button#checkout.button-1.checkout-button? If so, I'm not aware of a way to copy-paste this, or a name for it, but it is constructed with the format
htmlTag#idOfElement.class.with.periods.instead.of.spaces
It is pretty commonly a unique selector for the element in question.

On Smalltalk IDEs (Squeak, VisualWorks, etc), how can you navigate away from a message's code you're working on to inspect another?

In every IDE I've tried so far, if I'm partway through writing a message and need to look at the code of another, the browser asks me if I want to save. But if I say I do want to save, it actually tries to compile/syntax check the code, and refuses to perform the save if it does not pass. The only way to view the source of another message seems to be to say "no" to save and have everything wiped. How can I look at another class incidentally, or save code I am partway through working on that might not build right now?
Smalltalk is a multi-browser system. You'll need to have lots of different browsers open. Smalltalk is opinionated. The system browser (Nautilus) doesn't make it easy to view long methods, steering you towards writing short ones. It doesn't make it easy to have non-compiling code in a method, to steer you towards making small changes.
Experimental/prototypical code you might want to have in a Workspace/Playground. That can save to disk.
We are aware that it is an issue for people new to Smalltalk. We tried some fixes, they were a lot worse.
For now there is no easy way to do that. The two easiest opting are
Make the current method syntactically correct and save it.
Open another browser. If you want to see a class or method that is in your current code, you can cmd+click it or use "browse it", "implementors of", shortcuts that will open another window.
Also in pharo you can use GTSpotter to quickly find what you are looking for and preview its source code
When you say "this seems like a pretty huge thing to be missing,
and it could be gotten around by just having the option to use
a regular editor" I'm afraid you've entirely missed the point.
Understandable, though -- happens to us all.
Or did. Perhaps it was long ago, but we
were all there.
You might be thinking about the task in terms of
scrolling a giant text up and down to find what
you want. Scroll up -- read a little -- scroll back --
and continue making your changes.
And when you say " I can't imagine any circumstance
where it is OK, in pursuit of any agenda, to throw away
the coder's work against their will "
you are spot on correct, of course.
Imagine -- scrolling around, making dozens of little changes,
and before you've saved them -- poof -- they're all thrown away --
a mistake, perhaps, but completely against your will.
That would be awful. We're agreed.
(In fact, the editor I'm using to type this
is like that -- I can scroll around the whole thing,
making little improvements, all over, but it could
all go --poof-- and disappear, All of it.
Fairly common occurrence, when editing the web.
)
So let's try another run through that same task.
You get one little teensy, DUMB AS A POST editor,
where you can only see one thing at a time.
And now you just want to scroll somewhere else,
for a moment, and come right back.
Which actually means that
you are attempting to look up a second method,
while already changing a first method
(which would require the browser toforget the
context of the first method, and move to the second).
The browser does not know how long you will be away
from this context. You might go chaining along from
place to place, stop and read an email, take a call,
and go to lunch.
So, the browser cautions
"Hey - want to save this first?"
as if to say:
"
Hey - I can't imagine any circumstance where it is OK,
in pursuit of any agenda, to throw away the coder's work
against their will.
So listen up, coder.
You want to save this first?
"
But you can't save it.
You must first look something up.
Conundrum.
Ah-ha! There is a list of methods in that other pane.
One of them is highlighted.
Not those -- that one.
Double click that one.
The one you're already in.
As if to say
" Thanks. Good catch.
Yes, I know - can't though.
I need to change contexts.
You stay right here.
And give me another context
to go wandering about in.
please.
"
Soon, I expect, they'll start actually talking.

Access closure property names in the content block at runtime

I want to evaluate my content blocks before running my test suite but the closures' property names is in bytecode already. I'm ooking for the cleanest solution (compared with parsing source manually).
Already tried solution outlined in this post (and I'd still wind up doing some RegEx/parsing) but could only get it to work via script execution engine. It failed in IDE and GroovyConsole. Rather than embedding a Groovy script in project's code, I thought I'd try using Geb's native classes.
Is building on the suggestion about extending Geb Navigators here viable for Geb's PageContentSupport class whose contentTemplates contain a LinkedHashMap of exactly what I need? If yes, would someone provide guidance? If no, any suggestions?
It is currently not possible to get hold of all content elements for a given page/module. Feel free to create an issue for this in Geb's bug tracker, but remember that all that Geb can provide is either a list of content element names or a map from these names to closures that create these elements.
Having that information isn't a generic solution to your problem because it's possible for content elements to take parameters and there are situations where your content elements will be available on the page only after some other actions are performed (for example you have to click on button to reveal a section of a page that uses ajax to retrieve it's content). So I'm afraid that simply going over all elements and checking if they don't throw any errors will not cut it.
I'm still struggling to see what would "evaluating" all content elements prior to running the suite buy you. Are you after verifying that your content elements still work to get a faster feedback than running the whole suite? I'm pretty sure that you won't be able to fully automate detection of content definitions that don't work anymore. In my view it will be more effort than it's worth.

Conditional check in Selenium IDE

I want to check whether a possibly mandatory field is filled in using selenium. I would very much prefer to do this using the IDE rather than exporting to code.
To be more specific, I want to make sure that a post code field is filled in if the value of the country drop down list is 'United Kingdom'. The post code field can be left blank if the drop down list is set to anything else.
If the consensus is that I have to export and do the test in code, then I will, but I would be a lot happier if I could sort this out just through the IDE.
Unfortunately, Selenium-IDE does not offer any flow control functionality by default. However, the Flow Control plugin introduces a few new commands - while, gotoIf, label and the ...andWait variants. Using these, you should be able to check the currently selected value in the dropdown menu, and jump past a verify command if the value is not "United Kingdom".
Fair warning; it's not the easiest thing in the world to work with. For anything beyond very basic flow control, you'd probably be better off exporting to code anyway. But, it's an option for when you really want to push the IDE!