So the basic spiel, "I am new to this thing" called Selenium using Facebook's PHP Webdriver (https://github.com/facebook/php-webdriver) and I cannot find anything that matches "How to open a new tab in chrome" using this particular technology. Any help will be very much appreciated.
A virtual cup of coffee to you, kind programmer!
New way to do it since php-webdriver 1.10.0:
// Default behavior, without specifying window type
$driver->switchTo()->newWindow();
// Open new window
$driver->switchTo()->newWindow(WebDriverTargetLocator::WINDOW_TYPE_WINDOW);
// Open new tab
$driver->switchTo()->newWindow(WebDriverTargetLocator::WINDOW_TYPE_TAB);
$driver->switchTo()->window($driver->getWindowHandles()[1]);
See doucmentation for more examples.
You can go with JS solution like:
$webdriver->executeScript("window.open('". $url ."','_blank');", array());
Something like this should work:
$driver = RemoteWebDriver::create($host, DesiredCapabilities::chrome());
$driver->get('http://mine.com');
// Via driver: http://facebook.github.io/php-webdriver/classes/RemoteWebDriver.html#property_keyboard
$kbd = $driver->getKeyboard();
$kbd->sendKeys(WebDriverKeys.CONTROL,'t');
// Via an element: http://facebook.github.io/php-webdriver/classes/WebDriverElement.html#method_sendKeys
$element = $driver->findElement(WebDriverBy::id('somethingOnScreen'));
$element->sendKeys(WebDriverKeys.CONTROL,'t');
$driver->getKeyboard()->sendKeys(
array(WebDriverKeys::CONTROL, 't'),
);
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
So I am trying to parse HTMl from a website but all I get is menu because body has a preloader. Links are NSFW so I added a wildcard to them. My question is how do I parse whole page and not only menu? Creating a timeout doesn't seem to help (or I am doing the timeout wrong).
<?php
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 50
)
)
);
$stars_list_page = file_get_contents("https://www.por*pics.com/?q=blue+angel", 0, $ctx);
$dom_obj = new DOMDocument();
#$dom_obj->loadHTML($stars_list_page);
var_dump($dom_obj);
?>
You have menu only, because everything else loaded by js. Thats not going to be simple but you can try to execute js serverside, described here:
Execute javascript in PHP
But js loading can be domain restricted, so it may not help.
6 months later I realize how rude I was and didn't answer my own question for future visitors after finding solution.
I went to network tab in developer tools and under XHR I found the URL server is making requests towards to load more data.
If you are having trouble recreating the request try this awesome tool, works with more languages:
https://curl.trillworks.com/
I have a website, using tiny_mce backoffice.
My website works well on my server, but I have to change the host server and suddenly I see this problem:
For example:
If I want to save text with links, for wikipedia.org for example... And I save on backoffice (with open new window propertie _target)
-Then in website interface, I click on wikipedia text link
and and instead of opening a new window, I have somethinfg like this :
mysite.com//"//"////"http://wikipedia.org/"////"//"/"
Is that normal?
Last server never happen that
And in this new server he creates somethink like a mask
anyone knows how to resolve that?
thanks
best regards
You should use stripslashes();
http://php.net/manual/en/function.stripslashes.php
EXAMPLE
<textarea class="tiny_mce"><?php echo stripslashes(); ?></textarea>
It's pretty simple. i'm calling an PHP script from my flash using navigateToURL. It runs the script and opens a new window in my browser
It's possible to just call the php script from AS3, without open a new window ?
Thanks.
Are you looking to download information from the PHP script in to your app?
If so, you might be looking for URLLoader.
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLLoader.html
You can specify the target like so:
navigateToURL(myRequest, '_self');
Hope that helps!
flash.net.sendToUrl() may be of use.
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/package.html
I'm trying to generate website thumbnails programatically in PHP. To do this, I'm using imagegrabwindow() with a COM object:
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate($pre.$URL);
while ($browser->Busy)
{
com_message_pump(4000);
}
$img = imagegrabwindow($handle);
What I'm wondering is if there is any way to do the same thing with Firefox or Chrome? Can I invoke either of them with PHP COM?
You can invoke them with an exec command to the commandline. The Pearl Crescent Page Saver plugin for Firefox will take commandline arguments to save a capture of the page as well.
http://pearlcrescent.com/products/pagesaver/doc/#commandline
The Basic version gives you less flexibility than their paid version, but the basic version met my needs. It may also work on non-Windows systems, but I haven't tried it.
I tried the Com Object with IE and imagegrabwindow and I just got randomly blacked-out documents. Not finding any help to resolve that situation, scripting a plugin from the commandline seemed the next best viable option.