Which option finds elements based on the driver's underlying CSS selector engine in WebDriver Selenium - selenium-webdriver

Select the variation which finds elements based on the drivers underlying CSS selector engine in Web driver Selenium and why?
By.cssSelector ;
By.cssSelection ;
By.cssSelector()
By.cssSelected
I'm confused between option 1 and 3.

In Selenium Java you write:
driver.findElement(By.cssSelector("elementCssSelector"));
So the answer is:
c) By.cssSelector()

Related

is driver.getContextHandles() or driver.context() removed in Selenium4 as these methods are coming for Appium driver?

Is driver.getContextHandles() or driver.context() removed in Selenium4 as these methods are coming for Appium driver?
I am Using Selenium 4.1.1 and JavaClient- 8.0.0-beta2.
Facing issue to find element while running a test in Hybrind app.
Scenario
A Web view is opening in App post click of an icon. Element not found exception is coming whereas element is uniquely found/identified in Chrome.
Any suggestions in this will help to procced further.
Regarding the question about driver.context()
This moved to io.appium.java_client.remote.SupportsContextSwitching interface which also includes the default implementation.
In your tests if you're using AppiumDriver, just cast the driver, like:
io.appium.java_client.remote.SupportsContextSwitching
((SupportsContextSwitching) driver).getContextHandles();
NOTE: To have this work without ClassCastException, the driver initially should be created as AndroidDriver or IOSDriver, e.g.:
BaseOptions options = new UiAutomator2Options().setAutoGrantPermissions(true);
AppiumDriver driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), options);
More Details
I mention this, because driver.context() is a special case of a larger context.
There are a lot of changes in appium java client version 8 from version 7.
One of them: A lot of platform-specific and not defined by W3C WebDriver standard methods moved out to additional interfaces.
So pure AppiumDriver doesn't have this methods.
But if we look throught the code, e.g. to AndroidDriver, we see it implements 20+ additional interfaces:
public class AndroidDriver extends AppiumDriver implements
PressesKey,
SupportsRotation,
SupportsContextSwitching,
SupportsLocation,
PerformsTouchActions,
HidesKeyboard,
HasDeviceTime,
...
and the same for IOSDriver.
If you cannot find some method in AppiumDriver, try to go throught the interfaces, which AndroidDriver/ IOSDriver are implementing.

Using Selenium Commands on HTML content stored in a local varialble

This may sound odd BUT Is it possible to use WebDriver commands on a static variable that holds the html source? (eg: findElementbyId)
This is what i want to do:
set firefox webDriver
open website url
save the HTML pageSource to a "static local variable"
quit webDriver
Now - i want to be able to findElements and texts within this locally stored PageSource. (preferably using the selenium commands)
Any help and/or suggestion is greatly appreciated.
Thanks.
Basically no, it falls down at (5). The FirefoxDriver needs to communicate with an actual Firefox browser using the WebDriver protocol. Selenium can't work with just a String.
It's not clear what your use case is, but you could do things like copy the HTML to a temporary file, generate a file: URL for it, load it with the HtmlUnit or PhantomJS drivers and re-run your tests in-memory.
Surely plain old regular expressions, or an HTML parser like JSoup, are better options for post-processing HTML?

What is the most reliable .net selenium web driver?

In using .net selenium webdrivers, I have been stumbling in 2 main issues, each for a different specific webdriver.
The table below shows the issues Chrome and Firefox webdrivers have been falling short with me:
I am using RellYa's selenium jquery extensions.
Chrome webdriver randomly throws a jQuery not found exception. If I try a couple of times, I eventually succeed.
With Firefox's webdriver, this never happened.
On the other hand, firefox throws a
Unable to bind to locking port 7054 within 45000 ms
Research shows that the reason behind this is that I must have left another firefox webdriver not closed/not quit. But this defeats my using selenium to automate web tasks, in a multi threaded manner. I mean, after a couple of threads are opened, seems it reaches some limit and waits for one of the opened webdrivers to close.
Actually, from this firefox webdriver's documentation, they make it clear that only one instance is supposed to be running. What one is supposed to do then if he had in mind multi threading ?
Does any one have working solutions for the problems singled out in the table, for each specific webdriver implementations ?
No, you can run multiple instances of firefox, chrome, or whatever from your machine at any one time. If you research "Selenium Grid", you will see that it is designed to do that.
So:
The unable to bind message on firefox is not caused by another driver locking a port. Each driver instance starts on its own open port.
If you are not using Selenium Grid, or not using the grid, and are trying to handle the multi-threading yourself, just be careful of how you open and close your browsers in your #Configuration phases in your test runner.
As a educated guess, if you have instability, its more likely because you are trying to control a newer browser with a too-old version of Selenium? We need more info on your question, such as an example project to look at.

Is it possible to run phantomjs by using IE desired capabilities?

By default phantomjs uses chrome capabilities. Is it possible to run it with IE capabilities .If so, I need to use it for page-object gem like:
#browser = Watir::Browser.new(:phantomjs, args: '--ignore-ssl-errors=true')
Can any body please provide me any solution for it.
The quick answer is no: Phantom is using the same WebKit rendering engine that Chrome/Safari uses (*), so cannot act like IE.
You might be interested in TrifleJS which is a headless IE port of PhantomJS. (The project is in the early stages, and (AFAIK) won't work with CasperJS yet, and does not seem to support selenium integration either yet.)
*: More precisely, Phantom 1.9 is equivalent to about Chrome 13. And recent versions of Chrome use Blink, not WebKit. So Phantom 2.x, when finally released, won't be equivalent to any version of Chrome.

How to execute Robot Framework (SELENIUM) Ride Test cases in parallel

I have written my RF testcases using reusable keywords (built using native selenium webdriver not using Selenium2Library) and It works fine on single instance for what so ever browser I run.
But, I would like to execute these testcases in parallel on
1) Same machine different browsers
2) Different machine all browsers
Does Selenium Grid have native support to Robot Framework test cases? Or have any body found an alternative?
Yes, Robot Framework has native support for Java and Selenium2 within your defined "keyword" code blocks. All you do is use RemoteWebDriver in your keyword phrases instead of using WebDriver . This requires you run a Hub and a Node for the RemoteWebDriver to refer to, of course, or you can use a Sauce Labs account. Using Grid and Node you can run parallel tests with very little effort.
If you don't want to use RemoteWebDriver, you can still use WebDriver locally but you need to run parallel tests using "Maven surefire with threads" or a Gradle task with --parallel-threads=3" option. I have examples of this that you can see in my GitHub account.

Resources