I am using facebook php webdriver and I want to use Actions class to mouse hover on an element, trying different ways to do so, but not working. please help me where I am going wrong!
Here is the code-
{
$this->webDriver->get($this->url);
$id = $this->webDriver->findElement(WebDriverBy::id("email"));
$id->sendKeys("email");
$pass = $this->webDriver->findElement(WebDriverBy::id("password"));
$pass->sendKeys("passwd");
$login = $this->webDriver->findElement(WebDriverBy::xpath("//input[#value='Login']"));
$login->click();
$this->assertContains('dashboard/site',$this->webDriver->getCurrentURL());
$this->webDriver->findElement(WebDriverBy::xpath("html/body/nav[2]/div/ul/li[1]/a"))->click();
$this->webDriver->findElement(WebDriverBy::xpath("//a[contains(text(),'Care Pathways')]"))->click();
$this->webDriver->findElement(WebDriverBy::xpath("//input[#type='search']"))->sendKeys("QA Harness: Test1");
$element = $this->webDriver->findElement(WebDriverBy::xpath(".//*[#id='package-list']/tbody/tr/td[1]/a/i"));
$this->webDriver->moveToElement(WebDriverElement:: $element->isDisplayed())->perform();
//$this->webDriver->action(WebDriverActions:: )->moveToElement($element)->perform();
//$this->webDriver->getMouse()->mouseMove($element->getCoordinates());
// $this->webDriver->getMouse()->click();
//$this->webDriver->findElement(WebDriverBy::xpath("html/body/div[1]/div/div[1]/a[3]"))->click();
}
}
Use this
$action = new WebDriverActions($this->driver);
$action->moveToElement($element_you_want)->perform();
use(this for remote webdrivers):
$action = $this->driver->action();
$action->moveToElement($element_you_want)->perform();
Related
<?php
require 'vendor/autoload.php';
use Nesk\Rialto\Data\JsFunction;
use Nesk\Puphpeteer\Puppeteer;
use Nesk\Puphpeteer\Resources\ElementHandle;
class test{
public function startElement(){
$puppeteer = new Puppeteer();
$browser = $puppeteer->launch([
'headless' =>false,
'executablePath' =>"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
'defaultViewport'=> null,
'args'=> ['--lang=en-ru']
]);
$page = $browser->newPage();
$page->setDefaultNavigationTimeout(0);
$page->goto('URL');
$page->waitForTimeout(1000);
$username = $page->querySelector('#UserName');
$username->focus();
$page->keyboard->type('username');
$page->waitForTimeout(500);
$password = $page->querySelector('#Password');
$password->type('password');
$btn = $page->querySelector('.btn.btn-default');
$btn->focus();
$page->keyboard->press('Enter');
$page->waitForTimeout(5000);
header("Location: ../index.php?Input=SUCCESS");
}
}
?>
I tried to use Nesk\Puphpeteer\Resources\ElementHandle;
so that I can click or type on element or input as it is done on puppeteer nodejs,
when I run the code it doesn’t give me an error, but it can’t find this element on the page (the element is correct, I tried it on puppeteer nodejs everything worked correctly)
I saw in some codes on Nesk\Puphpeteer that they use class and public, I added them and the code did not run and does not give any errors. how can i fix this
I am very new to PHP and just got everything up and running. I am trying to self teach and I don't understand why my click function is failing. It sometimes will not process at all and other times I get the following error: https://www.screencast.com/t/ogZPogsLXjJ
<?php
require_once('vendor/autoload.php');
$host = 'http://localhost:4444/wd/hub';
$driver = RemoteWebDriver::create($host, DesiredCapabilities::firefox());
$driver->get('https://github.com');
$driver->findElement(WebDriverBy::xpath('/html/body/div[1]/header/div/div[2]/nav/ul/li[2]/a'))->click();
?>
I got it working:
$element = $driver->findElement(WebDriverBy::xpath('/html/body/div[1]/header/div/div[2]/nav/ul/li[2]/a'));
if ($element->isDisplayed()) {
$element->click();
}
Im trying to figure out how to call functions based on what a user clicks on a form. But im not sure if im doing it right.
I have a number of classes, lets say 3 for different ways to connect to a site, the user clicks on which one they would like.
FTP
SFTP
SSH
Which i have named 'service' in my code.
I don't want to run a whole bunch of IF statements, i would rather try and build the call dynamically.
What i have at the moment is as follows
$ftp_backup = new FTPBackup;
$sftp_backup = new SFTPBackup;
$ssh_backup = new SSHBackup;
$service = $request->input('service') . '_backup';
$service->testConn($request);
Im getting the following error
Call to a member function testConn() on string
Im not sure im doing this right.
Any help would be greatly appreciated.
Thanks
First of all $service is a string on which You cannot call method, because it is not an object (class instance).
I think it is a great example of where You can use Strategy Pattern which look like that:
class BackupStrategy {
private $strategy = null;
public function __construct($service_name)
{
switch ($service_name) {
case "ftp":
$this->strategy = new FTPBackup();
break;
case "sftp":
$this->strategy = new SFTPBackup();
break;
case "ssh":
$this->strategy = new SSHBackup();
break;
}
}
public function testConn()
{
return $this->strategy->testConn();
}
}
And then in place where You want to call it You call it by:
$service = new BackupStrategy($request->input('service'));
$service->testConn($request);
I suggest You to read about Design Patterns in OOP - it will help You a lot in the future.
How about this:
$ftp_backup = new FTPBackup;
$sftp_backup = new SFTPBackup;
$ssh_backup = new SSHBackup;
$service = $request->input('service') . '_backup';
${$service}->testConn($request);
This is called "Variables variable": http://php.net/manual/en/language.variables.variable.php
// Create class name
$className = $request->get('service') . '_backup';
// Create class instance
$service = new $className();
// Use it as you want
$service->testConn($request);
I dont ask many questions as I like to research for myself but this has me stumped.
I have an existing Codeigniter2(CI) application and am trying to integrate an existing API for a payment system (MangoPay). I have added it as a library and also preloaded it in autoload.php, it is being included with no errors.
My question is about setting up the class structure and addressing the class from my application.
Now, if you were to get this working from a plain old PHP file, the code would look like this (and btw it works on my machine with no issue from a plain php file)
<?php
require_once('../vendor/autoload.php');
$mangoPayApi = new MangoPay\MangoPayApi();
$mangoPayApi->Config->ClientId = 'user_id';
$mangoPayApi->Config->ClientPassword = 'password_here';
$mangoPayApi->Config->TemporaryFolder = 'c:\\wamp\\tmp/';
$User = new MangoPay\UserNatural();
$User->Email = "test_natural#testmangopay.com";
$User->FirstName = "Bob";
$User->LastName = "Briant";
$User->Birthday = 121271;
$User->Nationality = "FR";
$User->CountryOfResidence = "ZA";
$result = $mangoPayApi->Users->Create($User);
var_dump($result);
?>
So, I have created a new class in the libraries folder and if i was to var_dump() the contents of mangoPayApi as below, it throws all kinds of stuff which proves that it is working (ie no PHP errors).
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once('/vendor/autoload.php');
class MangoPayService {
private $mangoPayApi;
private $user;
public function __construct()
{
$this->mangoPayApi = new MangoPay\MangoPayApi();
$this->mangoPayApi->Config->ClientId = 'user_id_here';
$this->mangoPayApi->Config->ClientPassword = 'password_here';
$this->mangoPayApi->Config->TemporaryFolder = 'c:\\wamp\\tmp/';
//var_dump($mangoPayApi);
}
I thought I could just write a method in the class like this
function add_user(){
//CREATE NATURAL USER
$this->user = new user();
$user->Email = 'test_natural#testmangopay.com';
$user->FirstName = "John";
$user->LastName = "Smith";
$user->Birthday = 121271;
$user->Nationality = "FR";
$user->CountryOfResidence = "ZA";
$add_userResult = $this->mangoPayApi->Users->Create($user);
var_dump($add_userResult);
}
and acces it in my application like
<?php echo $this->mangopayservice->add_user() ?>
But i get errors Fatal error: Class 'user' not found in C:\wamp\www\mpapp\application\libraries\MangoPayService.php on line 25 (which is this->user = new user(); this line)
Can anyone explain how to correctly set up this scenario and how to integrate correctly with the API.
if I can get something to create a user simply when a page is opened, I think I can work it from there using the solution as a roadmap.
I will be writing all the integration code once I understand how to make this work.
Thank in advance
MangoPay requires a NaturalUser class. You try to instantiate a user class.
Simply replace your first line of the add_user function with :
$user = new MangoPay\UserNatural();
I found a problem that I not sure if is a bug of the php or on my code (probably mine) so let me show you what is happening:
<?php namespace MyApp\Conciliation;
use SimpleExcel\SimpleExcel;
use ForceUTF8\Encoding;
use MyApp\Conciliation\Gol;
class Conciliation {
protected function equalizeFile($file, $providerName)
{
$type = false;
$nfile = 'public'.$file;
// TEST 1: the ideal aproach. not working (see error#1 bellow)
$provider = new $providerName();
// TEST 2: working, getting the correct response
$provider = new Gol();
// TEST 3: working, getting the correct response
$provider = new MyApp\Conciliation\Gol();
$provider->equalize($nfile);
}
Note, the $providerName = 'Gol';
error1
Class 'Gol' not found
http://inft.ly/N8Q6F4B
So, there is any way that I could keeping using variables to instantiate aliases similar as above?
Edit, Problem solved: working example
<?php namespace MyApp\Conciliation;
use SimpleExcel\SimpleExcel;
use ForceUTF8\Encoding;
class Conciliation {
protected function equalizeFile($file, $providerName)
{
$type = false;
$nfile = 'public'.$file;
$providerName = "MyApp\\Conciliation\\".$providerName;
$provider = new $providerName();
$provider->equalize($nfile);
}
http://php.net/manual/en/language.namespaces.dynamic.php
If you are calling the class dynamically, you have to use the full path to the class.
So, your call to equalizeFile should be something like:
equalizeFile("myFile", "MyApp\\Conciliation\\Gol");