I need to double click an dom element using Selenium Webdriver - Facebook PHP library.
There's no direct way to perform a double click on the element, but there's a way over WebDriverMouse this is how far I've got.
$myElement = $myWebDriver->findElement(WebDriverBy::id('myElement'));
$myWebDriver->getMouse()->doubleClick($myElement->getLocation());
Unfortunately this isn't working since ->getLocation returns an instance of WebDriverPoint but the method ->doubleClick() needs an instance of WebDriverCoordinates.
Is there an easier way to perform the double click or is there a way do create a WebDriverCoordinates instance out of a WebDriverPoint object?
Thank you very much for you help.
Sorry, was to fast with the question. Just figured it out:
$myElement = $myWebDriver->findElement(WebDriverBy::id('myElement'));
$myWebDriver->getMouse()->doubleClick($myElement->getCoordinates());
Here is an alternative using the action builder.
$myElement = $myWebDriver->findElement(WebDriverBy::id('myElement'));
$driver->actions()->doubleClick()->perform();
Also, $driver->actions() allows action chain / composite actions.
Drag and Drop example:
$driver->actions()->mouseDown($source)
->mouseMove($target)
->mouseUp($target);
->perform();
But actually, you can do drag and drop by just one method.
$driver->actions()->dragAndDrop($source, $target)->perform();
Related
I want to scroll to an element using Symfony Panther but without using the javascript method.
Does anybody know a way to do that?
The javascript method is something like this:
<?php
// autoload here
$client = Client::createChromeClient();
$client->executeScript('document.getElementById("someElementId").scrollIntoView();');
Use the client that is the representations of the browser. For instance:
$client = Client::createChromeClient();
$client->getKeyboard()->pressKey(WebDriverKeys::PAGE_DOWN);
of course as you can interact with the mouse or keyboard to scroll down in the browser there are also other possibilities how can you do that. The PageDown is just an example
There are many more interesting functions inside just check the sources
In angular 2, it possible to set values within the html view of a component like this? It's already rendered in PHP:
//html page:
<dropdown [(options)]="['Available', 'Busy', 'Away', 'Offline']"></dropdown>
I have never seen this done anywhere online, so I assume it can't be done. But is there a workaround? For example if I had 100 dropdown components on the page with their own options model, I'd potentially have to make 100 requests to the server if doing it the angular way.
Thoughts?
//html page:
<dropdown [options]="['Available', 'Busy', 'Away', 'Offline']"></dropdown>
This template is perfectly OK for angular, as long as you use it for one-way binding using [prop]="expression" or prop="{{expression}}",
WORKING PLUNKER
because the moment you try to do two-way binding [(prop)]="expression" over an Array Value it will fail, that's because expression must be a component property to do two-way binding.
It will throw a Teplate parse error, to be precise.
BROKEN PLUNKER
1) Is there a way to send a Tab key through to the browser to test the tab index of a page?
2) Is there a way to send a W key through to the browser while also simulating the holding down of the cmd key to close a tab in chrome?
We have tried using the keyPress() function, and have also used the following function with jQuery:
/**
* #Given /^(?:|I )manually press "([^"]*)"$/
*/
public function manuallyPress($key)
{
$script = "jQuery.event.trigger({ type : 'keypress', which : '" . $key . "' });";
$this->getSession()->evaluateScript($script);
}
Neither of them will behave as expected (they do not seem to be working at all).
Has anyone got a solution to this problem?
I've spent a fair bit of time on this issue and here are my results:
Behat does not have a pre-defined step to just send keys to any element on the page. It does have pressKey method (#Given I press the :char key in the :field field), but it works only with field as a target of the key event. You would have to write your own pressKey to send keys to a custom CSS element
Behat uses Selenium, which in its turn uses JS Syn library to symulate synthetic browser events. This library is injected into the page by Selenium.
Selenium uses Syn.trigger('keydown',...) to send characters to elements, but it does not seem to work as expected. Instead, using Syn.key(DOMElement, 'tab') would actually send the tab key to the DOMElement element. You would have to implement this as well to make your pressKey work as expected.
Behat is written using Symfony components and uses DriverFactory class to create drivers, including selenium driver. For some reason, the Selenium2Driver class is hardcoded, so there is no way to inject your own extended implementation of this class. You would have to use reflection to piggy-back on exiting protected methods of Selenium2Driver class to include Syn library and execute JS code from previous step.
There is a special case for tab key triggered in window without target element focused - this is the case when you want to test something like Skip to content accessibility link. Such link should appear on first Tab character press, but Syncan tab only from another element that can receive focus.
A working solution is to inject such element as a very first element after opening <body> tag. This element would be visually hidden, but compatible with screen readers. Then we trigger key on this element to make sure that an element that supposed to get the very first focus from tab index actually gets it. Note that injecting element and triggering key press on it does not make it focused itself.
The good news is that it is all doable and is working for me. The bad news is that, unfortunately, I cannot share the code (well, at least not this version and not just yet) :(
I used the auto-complete function in jquery. It's data source are the results from a php-back-end.
$("#ice_id").autocomplete("ice-ver.php", { extraParams : { flavour_id: $("#flavour_id").val() } });
Let us take following example:
We type in the flavour ID 3992 ...(and 3992 exists in the database and is properly returned by the php backend). If we type in now 3992999 the auto-complete function should top showing anything up ...but unfortunately it still does, (could the problem lie within the fact that I am using integers instead of strings or chars?)
Thanks in advance for any hints and
best regards
Daniyal
if it's showing something doesn't that mean there is a result from the php code? Check if it's really how you want it, and if you post it someone might be able to help
I agree with shyam. It seems like your PHP-code returns values. Try to request the PHP-script directly in a browser through the-url-to-php-script?flavour_id=3992999.
There are different autocomplete plugins for jquery. If you instead use the one at jquery ui (http://jqueryui.com/demos/autocomplete) your entered value are automatically passed to the URL-resource as the parameter "term". See if that helps you in pinning down the problem with the PHP-script.
I am trying to control stuff with PHP from keyboard input. The way I am currently detecting keystrokes is with:
function read() {
$fp1=fopen("/dev/stdin", "r");
$input=fgets($fp1, 255);
fclose($fp1);
return $input;
}
print("What is your first name? ");
$first_name = read();
The problem is that it is not reading the keystrokes 'live'. I don't know if this is possible using this method, and I would imagine that this isn't the most effective way to do it either. My question is 1) if this is a good way to do it, then how can I get it to work so that as you type on the page, it will capture the keystrokes, and 2) if this is a bad way of doing it, how can I implement it better (maybe using ajax or something)?
edit: I am using PHP as a webpage, not command line.
I'm assuming that you're using PHP as a web-scripting language (not from the command line)...
From what I've seen, you'll want to use Javascript on the client side to read key inputs. Once the server delivers the page to the client, there's no PHP interaction. So using AJAX to read client key inputs and make calls back to the server is the way to go.
There's some more info on Javascript and detecting key presses here and some info on how to use AJAX here.
A neat option for jQuery is to use something like delayedObserver
If you are writing a CLI application (as opposed to a web application), you can use ncurses' getch() function to get a single key stroke. Good luck!
If you're not writing a CLI application, I would suggest following Andrew's answer.
Try readline:
http://us3.php.net/manual/en/function.readline.php