I am trying to send keys to browser(not element) using this code:
Actions action = new Actions(driver);
action.sendKeys("Hello! World!");
action.perform();
It works well in Chrome and IE8, but get the result World in Firefox!
I am using Firefox 22 and Selenium WebDriver 2.32.0
Is it a bug? Thank you.
Firefox 22 will not be supported until Selenium 2.34.0 (It may work for some scenarios at the moment, but generally speaking it doesn't work).
I would suggest rolling back to FF20 if you want Selenium 2.32.0 to work, or FF21 if you want to upgrade to Selenium 2.33.0.
Related
I am trying to build a scraping app using python and selenium and run it on a server. What it does is creating and scheduling posts on CreatorStudio to share them on Instagram. I can't use Chrome or Edge Chromium because I can't send emojis using send_keys on these browsers. Firefox on the other hand can send emojis. And I can't use copy-paste workaround because it's a server. send_keysworks fine on Firefox when I am trying to send keys to an input web element e.g: google search bar. But when I try to send keys to this element driver.find_element_by_xpath("//div[#class = '_1mf _1mj']"), It doesn't work on Firefox but it does on Chrome.
Is there any way to solve this issue?? Or is there any work arround or some java script I can run?
Thank you
If possible, try creating the element xpath using input tag. Otherwise you can use JavaScript Executor or Action class to send keys.
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("document.getElementById('elementID').setAttribute('value', 'new value for element')");
I'm able to use:
let browserLog = await browser.manage().logs().get('browser');
console.log(util.inspect(browserLog))
in chrome but, does not work for IE and Edge browsers.
Any suggestions?
You cannot. The only browser and driver that currently provides the console log is Chrome w/ Chromedriver. It may be added to the W3C Webdriver spec at a later date, follow this issue https://github.com/w3c/webdriver/issues/406
I am using WebDriver C# for Chrome Automation. I want to attach driver to already opened Chrome Instance.
I am struggling since long time; I hope here I got correct and proper answer.
As far as I know, attaching to an existing browser is not possible, and there are not plans to implement that functionality: https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/18.
I am trying to scrape a website that contains images using a headless Selenium.
Initially, the website populates 50 images. If you scroll down more and more images are loaded.
Windows 7 x64
python 2.7
recent install of selenium
[1] Non-Headless
Navigating to the website with selenium as follows:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get(url)
browser.execute_script('window.scrollBy(0, 10000)')
browser.page_source
This works (if anyone has a better suggestion please let me know).
I can continue to scrollBy() until I reach the end and then pull the source page.
[2] Headless with HTMLUNIT
from selenium import webdriver
driver = webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.HTMLUNIT)
driver.get(url)
I cannot use scrollBy() in this headless environment.
Any suggestions on how to scrape this kind of page?
Thanks
One option is to study the JavaScript to see how it calculates what to load next. Then implement that logic in your scraping client instead. Once you have done that, you can use faster scraping tools like Perl's WWW::Mechanize.
You need to enable JavaScript explicitly when using the HtmlUnit Driver:
driver.setJavascriptEnabled(true);
According to [http://code.google.com/p/selenium/wiki/HtmlUnitDriver](the docs), it should emulate IE's JavaScript handling by default.
When I tried the same method, I got error messages that selenium crashed while connecting java to simulate javascript.
I wrote the script into execute_script method then the code works well.
I guess the communication between selenium and java server part is not configured properly.
Enabling the javascript with HTMLUNITDRIVERWITHJS is possible and quick ;)
I'm not sure I quite understand the difference. WebDriver API also directly controls the browser of choice. When should you use selenium remote control (selenium RC) instead ?
Right now, my current situation is I am testing a web application by writing a suite with Selenium WebDriver API and letting it run on my computer. The tests are taking longer and longer to complete, so I have been searching for ways to run the tests on a Linux server.
If I use Selenium Remote Control, does this mean I have to rewrite everything I wrote with WebDriver API?
I am getting confused with Selenium Grid, Hudson, Selenium RC. I found a Selenium Grid plugin for Hudson, but not sure if this includes Selenium RC.
Am I taking the correct route? I envision the following architecture:
Hudson running on few Ubuntu dedicated servers.
Hudson running with Xvnc & Selenium Grid plugin. (Do I need to install Firefox separately ?)
Selenium grid running selenium RC test suites.
I think this is far more time efficient than running test on my current working desktop computer with WebDriver API.
WebDriver is now Selenium 2. The Selenium and WebDriver code bases are being merged. WebDriver gets over a number of issues that Selenium has and Selenium gets over a number of issues that Webdriver has.
If you have written your tests in Selenium one you don't have to rewrite them to work with Selenium 2. We, the core developers, have written it so that you create a browser instance and inject that into Selenium and your Selenium 1 tests will work in Selenium 2. I have put an example below for you.
// You may use any WebDriver implementation. Firefox is used here as an example
WebDriver driver = new FirefoxDriver();
// A "base url", used by selenium to resolve relative URLs
String baseUrl = "http://www.google.com";
// Create the Selenium implementation
Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
// Perform actions with selenium
selenium.open("http://www.google.com");
selenium.type("name=q", "cheese");
selenium.click("name=btnG");
Selenium 2 unfortunately has not been put into Selenium 2 but it shouldn't be too long until it has been added since we are hoping to reach beta in the next couple of months.
As far as I understand, Webdriver implementation started little later than Selenium RC. From my point of view, WebDriver is more flexible solution, which fixed some annoying problems of SeleniumRC.
WebDriver provides standard interface for testing web GUI. There are several implementations of this interface (HTTP, browser-specific and based on Selenium). Since you already have some WebDriver tests, you must be familiar with basic docs like this
The tests are getting longer and longer to complete, so I have been searching for ways to run the tests on a linux server.
Did you try to find actual bottlenecks? I'm not sure, that elimination of WebDriver layer will help. I think, most time is spent on Selenium commands sending and HTTP requests to system-under-test.
If I use sleneium remote control, does
this mean I have to rewrite everything
I wrote with WebDriver API ?
Generally, yes. If you did not implement some additional layer between tests code and WebDriver.
As for Selenium Grid:
You may start several Selenium RC instances on several different [virtual] nodes, then register them in Selenium Grid. Your tests connect to Selenium Grid, and it redirects all commands to SeleniumRC instances, coordinating them in accordance with required browsers.
For details of hudson plugin you may find more info here