Selenium - what is the difference between click and clickAndWait? - python

I am new to selenium and need some clarification on some stuff. I've tried click and clickAndWait in the IDE, and while the references stated clearly what each meant, when I export the test case to Python, it seems like both are doing the same thing here
driver.find_element_by_xpath("//li[#id='pa-u_8298348-bd']/a/span[2]").click() #click and wait
driver.find_element_by_link_text("IMVironments").click() #click
Can someone tell me what is the difference here then?

From Selenium docs:
Many Actions can be called with the "AndWait" suffix, e.g.
"clickAndWait". This suffix tells Selenium that the action will cause
the browser to make a call to the server, and that Selenium should
wait for a new page to load.

2 years later, I know. But I was looking for the same answer and found it.
From the Selenium Wiki
The AndWait alternative is always used when the action causes the browser to navigate to another page or reload the present one.
In other words, Selenium's webdriver, when utilizing the Click() command, will inherently use the "AndWait" modifier if it recognizes a page load.
See also Interface WebElement
void click()
Click this element. If this causes a new page to load, this method will attempt to block until the page has loaded.

I'm not sure if this is a python thing, but it appears you are only calling 'click' and are not calling 'clickAndWait'. I think this is what Trott is pointing out too.
With this said I have noticed that IE often requires AndWait a bit more often than Firefox or Chrome, which seem to deal with just click a bit better (due to speed?). You can also create your own 'wait' in Selenium, which is what I usually do in critical situations (as in you need to interact with a specific element so you 'wait' until it exists).
EDIT:
After your comment, I now understand what you are saying (was mildly confused about the 'clickandwait' comment :P). From what I can tell AndWait is not always available for the Python binding, I found that here, but I'll admit it's not 100% clear as it suggests otherwise in other places. Perhaps this would be useful instead?
wait_for_page_to_load(timeout)[source]
Waits for a new page to load.
You can use this command instead of the “AndWait” suffixes,
“clickAndWait”, “selectAndWait”, “typeAndWait” etc. (which are only
available in the JS API).
Placed this as an edit, because was too long for a comment, sorry!

Related

Selenium "sendkeys" does not work with a particular website but manually typing it in works

https://phytozome-next.jgi.doe.gov/blast-search
on this website if i use the blast tool with the sequence "MARPFTLSLLSLCLLLSAWSCFGGSSSTNRFNICQLNSLNALKPDHRVETDGGLVETWSSRHPELECAGVTVTRRTLYRNGFQMPSYSPYSQMIMAIQGKGALGLALSGCAETYEEPAKESSSSSQKPSDSHQKIRQFDQGHVMLIPRGVPFWIFNTGDEPLITVTLLDTSSEDNQLDQSPREFYLAGNPDIEHPEAMKEKQQQQAEEEGGNVLSGFGKRFLARALNIDQDTANKLISPDDEMKQIVKLKEGLSVISPKWQGQQEDEDEDDDDEDEDESVSRPSRRPSHGKRVHKEEETVVEPYPHGKHVHKEVEKEVEPLPPRKHVHKEEEKEIEPLPPRRSRHHHDEGEDEGEEEEKPRARRTRGPTPSPKGEGHRGVEEEDESEDTKGHKTRHEKTRHEKSWKEHRPEGEDVEKGEAHEEWETRPSKDKPHGSNGLDETICSSKLQFNIARPKGADFYNPKAGRIKNLNSQSLPALQHFGLSAQYVVLYKNGIYSPHWNMDANSVIYVIRGQGQVRVVNNEGIVMFDDELKKGQLLVVPQNFMVAEEAGDQGFEYVVFKTNDNAVTSYLKETFRAFPAEVLVNIYKLKHSQVHDLKYNGNLGPLVNPENSLDQSS"
along with Archaeplastida selected in order to return all results i get 100 results
when i use selenium with the chrome driver the web page informs me that "The Phytozome service couldn't get what you were after."
i have narrowed the problem down to something involving send keys, since if i run selenium all the way up to the point where it sends keys and i input the keys myself it works just fine.
When you say you "input the keys yourself", are you really typing those hundreds of random-looking letters yourself, one at a time? That looks about impossible.
It totally depends on the particular website's programming, but it could be a timing issue. You can try a separate SendKeys() call for each character with a pause between each one.
i am not sure what the problem was but i simply used execute script instead of send keys. that posed another issue, which i resolved by sending a space key and then clicking backspace.
i tried everything including sending the keys one by one with a space in between and this was the only thing that worked.

Python, Chrome Task Manager - Programmatically Access Chrome Task Manager's Text WITHOUT USING CHROMIUM

So, as many have encountered Chrome's memory usage can be debilitating so I want to PROGRAMMATICALLY access "Chrome's Task Manager" or something equivalent which displays Tabs, their PIDs, AND SUBFRAMES (if possible) so I can create a script to kill them. After a ton of reading, and a lot of answers suggesting that it might not be possible and some where the posters didn't answer the question, I'm just not sure that the answer to THIS question has truly definitively been given yet.
The closest I've gotten is using "chrome://system/" in the omnibox, but when you expand "mem_usage" it doesn't give you useful memory usage numbers per tab at all and lacks the subframes, but with this method I'd planned to use the tab titles to kill the tabs if I could have actually gotten their memory footprint.
I tried using the win32gui's FindWindowEx method to get the text, but that requires you to know the child element of the text displayed so I downloaded "Window Detective" to see the name of the element(s) the "Chrome Task Manager" displays, the PIDs, and Tab names for, but "Window Detective" only came back with the "EmbeddedMenuWindowClass" which is the entire Window, not related to the text displayed.
I made a fleeting effort to use Selenium, but it seems as though it's just not capable of grabbing Special Menus inside of Chrome over just grabbing tab names and elements within a webpage.
I also tried "pywinauto" but that thing's documentation is really, really bad. I've tried using the "connect" method, "hwndwrapper", etc. but grasping what parameters to use, how their being passed, and what to expect along with how to then use the output you get (such as a list of PIDs or Handles) is seriously bungled. I would have loved if the documentation included the OUTPUT so I could actually see what I'm supposed to get so I don't end up rabbit-holing only to find out that everything I've tested doesn't deliver what I'm looking for. Sorry if that sounds whiny, but I spent hours reading the PDF and the official docs and got badly frustrated.
I also tried launching chrome via the Command Line following this document for logging (http://www.chromium.org/for-testers/enable-logging), but it may be a Chromium only thing, but cannot find the logging document that's created and when I redirect its output to a file, I get nothing useful.
But yes, does anyone know how to programmatically access "Chrome Task Manager's" text, or something else that will deliver similar output? Thank you.
Why to just to use the python os module something like this:
import subprocess as sub
p = sub.Popen(['your command', 'arg1', 'arg2', ...],stdout=sub.PIPE,stderr=sub.PIPE)
output, errors = p.communicate()
print output
You can use the command ps to list all the proceses running in chrome however that only will give you the pid not the name of tab to get that I think the only way is to get the data directly from chorme by creating an extension.
https://developer.chrome.com/extensions/tabs

sel.click("xpath=//*[#id='seriesNwsHldr']/div[2]/p[1]/a") is not working

Exception: ERROR: Element xpath=//*[#id='seriesNwsHldr']/div[2]/p[1]/a not found.
I checked in Fierbug. The path is correct but I don't know what's the reason for this test case to fail.
It looks like a problem of timing. May be you can intentionally add wait time till the element appears on the page.
Another possibility is that element which you are trying to interact is hidden.
Would be great if you can post errors you are getting when you test fails.
Can I have the site for checking?
BTW sometimes you should to wait the loading of the page, so you need to do before of this action an instructions like:
clickAndWait(30000)
in my cases it solves a lotof problems :)

How do the Selenium bindings work, and how do I use them?

Note: This may be more of a "meta" issue of how to understand documentation rather than a specific issue with the Selenium bindings themselves.
I'm looking at the Selenium Python bindings, and I'm a bit confused.
Most examples of how to start a simple instance of the browser require something like this:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("www.google.com")
Now, I look at the webdriver.firefox object and I see that there are four methods associated with that object! I'm sure there should be more than this. Where, for instance, is .get() in my example?
So I start looking around and I see that there are a bunch of methods I can use on the webdriver.Firefox() object in webdriver.remote. But this doesn't seem to make sense? I'm not using webdriver.remote? Why are all these methods in here?
Finally, my confusion is compounded by the fact that there's selenium.selenium, which has a host of interesting and powerful methods, but I have no idea how to use them. Then don't work on the webdriver.Firefox() object, so how do I use them? Why do they never appear in any examples?
webdriver.Firefox() is in fact webdriver.firefox.WebDriver.
Just have a look on the code in selenium/webdriver/__init__.py and selenium/webdriver/firefox/webdriver.py, which inherits a lot from the RemoteWebDriver class.
There is a short introduction to the selenium python bindings, too. Have fun!

Selenium 2.0rc3 click function too fast?

First off, sorry for the cryptic question.
My team is currently using Selenium 2.0rc3 (with python) for testing our web app with chrome. When we used the 2.02b version of Selenium, our test passed (it was a little slow and we had small hacks that we added to webdriver). After we upgraded, the test became extremely fast and started failing. After debugging we found out most test failed because webdrivers click() function was not blocking() successive calls. Currently we added a sleep()/timeout of .5 secs after each click and while this solves the immediate problem, it doesn't quite achieve our main goal (which is to speed up our test)
Your problem is not really that it's clicking too fast. Just that it's clicking before that element is present. There are two ways to get round this:
Wait until the element is present before clicking
Increase the implicit wait time
I'm afraid I haven't used the WebDriver Python bindings. However, I can tell you how it is done in Java and hopefully you can find the Python equivalent yourself.
To wait for an element, we have in Java a class called WebDriverWait. You would write a Function which you pass to the until() method which passes only when the element exists. One way you could do that is with driver.findElements( By... ) or wrap driver.findElement( By... ) in an exception handler. The Function is polled till it returns true or the timeout specified is hit.
The second method is the preferred method for your case and in Java you can do driver.manage().timeouts().implicitlyWait( ... ).
I've tried the selenium-2 rc3 python bindings for chrome. My experience was the opposite of what you're describing - after clicking, the driver didn't know that the page was ready for it to continue. So instead of speeding up the tests, they turned out very slow (because the driver was waiting for ages). However, the firefox driver seems pretty stable - maybe you should stick with it until the chrome driver gets baked a bit more.
If the click() executes ajax calls I would suggest you to use NicelyResynchronizingAjaxController

Categories