How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium?

It should look like this: from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument(‘–headless’) options.add_argument(‘–disable-gpu’) # Last I checked this was necessary. driver = webdriver.Chrome(CHROMEDRIVER_PATH, chrome_options=options) This works for me using Python 3.6, I’m sure it’ll work for 2.7 too. Update 2018-10-26: These days you can just do this: from selenium import … Read more

Execute JavaScript using Selenium WebDriver in C#

The object, method, and property names in the .NET language bindings do not exactly correspond to those in the Java bindings. One of the principles of the project is that each language binding should “feel natural” to those comfortable coding in that language. In C#, the code you’d want for executing JavaScript is as follows … Read more

Selenium WebDriver: Wait for complex page with JavaScript to load

If anyone actually knew a general and always-applicable answer, it would have been implemented everywhere ages ago and would make our lives SO much easier. There are many things you can do, but every single one of them has a problem: As Ashwin Prabhu said, if you know the script well, you can observe its … Read more

Getting the return value of Javascript code in Selenium

To return a value, simply use the return JavaScript keyword in the string passed to the execute_script() method, e.g. >>> from selenium import webdriver >>> wd = webdriver.Firefox() >>> wd.get(“http://localhost/foo/bar”) >>> wd.execute_script(“return 5”) 5 >>> wd.execute_script(“return true”) True >>> wd.execute_script(“return {foo: ‘bar’}”) {u’foo’: u’bar’} >>> wd.execute_script(“return foobar()”) u’eli’

release Selenium chromedriver.exe from memory

per the Selenium API, you really should call browser.quit() as this method will close all windows and kills the process. You should still use browser.quit(). However: At my workplace, we’ve noticed a huge problem when trying to execute chromedriver tests in the Java platform, where the chromedriver.exe actually still exists even after using browser.quit(). To … Read more

Using XPATH to search text containing  

It seems that OpenQA, guys behind Selenium, have already addressed this problem. They defined some variables to explicitely match whitespaces. In my case, I need to use an XPATH similar to //td[text()=”${nbsp}”]. I reproduced here the text from OpenQA concerning this issue (found here): HTML automatically normalizes whitespace within elements, ignoring leading/trailing spaces and converting … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)