I am trying to get some elements with python selenium.
When I inspect, I make a right-click on the element of the page and it shows the code in the dom.
So I successfully identify the correct XPath.
But then, when I execute my python selenium script, it doesn't detect the nodes.
So I had a second look at the dom and I can see the nodes are hidden. They only show when I made an inspection on it.
Please look at this screenshot:
You can see in grey all the hidden elements.
Does anyone already face this scenario? How can I get these elements when they are hidden? is there a hack?
The "hidden" elements are script blocks. So you can't click on them as they are not part of the UI of the page, they are part of the logic. A script is just not clickable, it has no size, no color and no position.
Related
For our web application I wrote one selenium script, which is working very fine in my office workstation (which has big screen).
When I execute the same script for the same application in my laptop(which has small screen) it is not able to find the element.
Actually when I open the application in my laptop some elements are visible only when I scroll down the page but those element are visible in big screen without scrolling. Application view is automatically adjust as per the screen.
So, for these application how I can write the selenium script so that it will work any kind of screen ?
What do you mean by "it is not able to find the element"? Which error did it show?
In my own experience with automation, in some specific scenarios, the behavior of the app change when the scrollbar appears (for example, when I try to click on an element, it scrolls down to that element, but "jumps up" to the element above it - this I can reproduce manually.)
Some test scenarios are quite sensitive with scrollbar, for example drag&drop.
You should analyse each failed test separately and find a solution for each case.
Selenium cannot find element that is not visible, you must always check if element is visible and if not scroll to this element.
see this question Scroll Element into View with Selenium
I have a hidden div element that when I click the link the visibility changes. In my Selenium IDE script I click the link and I see the div open but then it immediately closes. The rest of the scripts run, but in a demo I would like to keep that div open.
My steps are:
click [Link that shows hidden div]
-->It is here that it displays and then immediately hides it.
focus [element inside div]
assertValue [target element]
Is there a setting that I need or a step that needs to be added?
It's hard to suggest. But there are some things that you can try.
First of all maybe your div is going to hide when link is not under
the mouse. Than you can use mouseOver
Maybe if you need just to verify variable you do not need even see
the div. Selenium IDE can take the value from element that is not
visible. It is not a fare play but sometimes you can do it.
Another way is to use javascript to bring your div to the light:
getEval | window.document.getElementById('your_divs_id').set_attribute('style','');
The most brutal and not trustable way to try to do it to add command
getEval | window.stop()
right after the click.
I am using Selenium IDE to test a tree.
I am having two elements with same parent element, one is a check box and the other is a text.
My question is, can I use the text element to make selenium click on the check box?!
in another way, can I connect the two elements to each others some how?!!
As for me I am right click on the browser webpage that I want to test. And I can easily chose by show all available command. Note that when you right click on the browser you need to open your selenium-ide.
Hope this will helpful.
I'm trying to find the location of some text on a web page using Selenium.
I can use the isTextPresent function to tell me if the text occurs, but then I want to know where it actually is.
The wider problem is that I want to click on this text.
The problem is that I don't seem to be able to click on this text, which I think is in some control embedded on the page. So, it doesn't seem to be detected as a link or button or option etc. However, I need to click on it to make a selection.
Any thoughts?
Your solution xpath=//*[text()='hello'] will click the first clickable element with the text "hello" in the source code. If you want to be more specific, you can add more cases to the xpath like this
xpath=//*[#id='exampleId']//*[text()='hello']
Now this will click element with text 'hello' that's found after some element with id 'exampleId'.
Xpath is great usage and you should answers above. However, I realised, that sometimes Selenium does not allow you to click something, because it thinks the text is hidden by CSS
So far I do not have any workaround for it and instead of clicking a button I am closing completly whole browser window.
But in my case its div hidden by CSS showing actual version number of such application. So I only take a screenshot of it:
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
File destination = new File("path/to/outputfiles/versionNumber.png");
FileUtils.copyFile(scrFile, destination);
Got it !
I don't know the answer to how to find the location,
but, the more important bit is to click on that text.
I can just use an XPath locator in the click method, like :-
Click(xpath=//*[text()="hello"])
This will click on the element that has a text value of "hello".
In my case, this is unique, so that's specific enough.
${x_axis}= Get Horizontal Position xpath=//*[text()="Log files"]
Get Horizontal Position returns the position of 'Log files' wrt the left end(X-axis length).
the position is an integer value... so can be compared easily as well.
I'm confused about the difference between the Click and ClickAt commands in selenium. Where can I use the ClickAt command?
Here are what Selenium IDE says about those two commands :
click(locator) Arguments:
locator : an element locator
Clicks on a link, button, checkbox or
radio button. If the click action
causes a new page to load (like a link
usually does), call waitForPageToLoad.
And :
clickAt(locator, coordString) Arguments:
locator : an element locator
coordString : specifies the x,y position (i.e. - 10,20) of the mouse
event relative to the element returned
by the locator.
Clicks on a link, button, checkbox or
radio button. If the click action
causes a new page to load (like a link
usually does), call waitForPageToLoad.
click is used when you just want to "click" on an element, like a button, a link, ...
And clickAt is used when you want to "click" on a position designated by mouse coordinates.
I suppose the second one can be useful for some "rich" applications -- I've actually never used it... On the other hand, I use click like all the time.
If you have a page with form elements, links, buttons, and stuff like that, you'll probably generally use click : it's way easier to find an element using it's id or classname than having to find it's position in pixels on the page ^^
I noticed some differences between click() and clickAt() when testing a ExtJS app.
For example, if I try to click a tab in a Ext.TabPanel, click() command does not work, although I provide it with an correct xpath, and clickAt() works fine.
Code looks like this:
click("//li[#id='tab-panel-id__second-tab-id']/a[2]/em/span/span")
doesn't work, but
clickAt("//li[#id='tab-panel-id__second-tab-id']/a[2]/em/span/span","0,0")
works.
Notice that coordinates are (0,0)
I can't figure out why this happens...
I'm testing a GWT application and it seems like I have to use clickAt if I want to click on a node in a tree widget.
Be careful when testing clickAt. Sometimes double clicking the command will cause it to show up red. You will change the line to try other alternatives but nothing will work. But then run your script and the clickAt line will be fine with whatever you type in.
There is a dojo widget at our application which only works with clickAt("//span[#id='mastheadIconBar']/span[1]/span/span","0,0").
Don't know why, but only click("//span[#id='mastheadIconBar']/span[1]/span/span") does not work.