Asked  8 Months ago    Answers:  5   Viewed   51 times

I'd like to use Selenium to automate a few web tasks (not for testing). I think I have Selenium RC Server installed, but have no way of writing "test scripts" since I can't find a client driver in PHP (see: http://seleniumhq.org/download/).

Is there a way for me to use Selenium with PHP? This seems to suggest I need PHPUnit http://www.phpunit.de/manual/current/en/selenium.html. I just want to automate a few tasks, not get involved with a full suite of testing.

 Answers

71

Try Following things

  1. Get Phpunit installed and working
  2. Also have JAVA sdk & jre on your pc.
  3. Now record test cases using selenium IDE.
  4. Export the testcases to php files.
  5. Using these exported functions create an library of test cases.
  6. Create suite which calls the functions/tests from library.
  7. Now to execute Start Selenium Server using java command.
  8. Using phpunit Execute the suite.

for refrence how to write these files click here and also try on git hub

Wednesday, March 31, 2021
 
PandemoniumSyndicate
answered 8 Months ago
76

You have two choices. You can save the PDF to a file and attach the file or else output it as a string. I find the string output is preferable:

$pdfString = $pdf->Output('dummy.pdf', 'S');

The file name is ignored since it just returns the encoded string. Now you can include the string in your email. I prefer to use PHPMailer when working with attachments like this. Use the AddStringAttachment method of PHPMailer to accomplish this:

$mailer->AddStringAttachment($pdfString, 'some_filename.pdf');
Wednesday, March 31, 2021
 
the_e
answered 8 Months ago
88

There are always the exec-familiy functions to execute/spawn another process.

Saturday, May 29, 2021
 
MassiveAttack
answered 5 Months ago
79

In the discussion entitled How does recaptcha 3 know I'm using selenium/chromedriver we have discussed about some generic approaches to avoid getting detected while web-scraping. Let's deep dive.


Headless Browser

A headless browser is a browser that can be used without a graphical interface. It can be controlled programmatically to automate tasks, such as doing tests or taking screenshots of webpages.


Why detect headless browser?

As per @AntoineVastel, headless browsers are used to automate malicious tasks. The most common cases are web scraping, increase advertisement impressions or look for vulnerabilities on a website.

Until an year ago, one of the most popular headless browser was PhantomJS. Since it is built on the Qt framework, it exhibits many differences compared to most popular browsers. It was possible to detect PhantomJS using some browser fingerprinting techniques. Since version 59, Google released a headless version of its Chrome browser. Unlike PhantomJS, it is based on a vanilla Chrome, and not on an external framework, making its presence more difficult to detect. So there are likely other ways to detect Chrome headless.


Detecting Chrome Headless

  • User agent: The user agent attribute is commonly used to detect the OS as well as the browser of the user. With Chrome version 59 it has the following value:

    Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/59.0.3071.115 Safari/537.36
    
    • A check for the presence of Chrome headless can be done through:

      if (/HeadlessChrome/.test(window.navigator.userAgent)) {
          console.log("Chrome headless detected");
      }
      
  • Plugins: navigator.plugins returns an array of plugins present in the browser. Typically, on Chrome we find default plugins, such as Chrome PDF viewer or Google Native Client. On the opposite, in headless mode, the array returned contains no plugin.

    • A check for the presence of Plugins can be done through:

      if(navigator.plugins.length == 0) {
          console.log("It may be Chrome headless");
      }
      
  • Languages: In Chrome two Javascript attributes enable to obtain languages used by the user: navigator.language and navigator.languages. The first one is the language of the browser UI, while the second one is an array of string representing the user’s preferred languages. However, in headless mode, navigator.languages returns an empty string.

    • A check for the presence of Languages can be done through:

      if(navigator.languages == "") {
           console.log("Chrome headless detected");
      }
      
  • WebGL: WebGL is an API to perform 3D rendering in an HTML canvas. With this API, it is possible to query for the vendor of the graphic driver as well as the renderer of the graphic driver. With a vanilla Chrome and Linux, we can obtain the following values for renderer and vendor: Google SwiftShader and Google Inc.. In headless mode, we can obtain Mesa OffScreen, which is the technology used for rendering without using any sort of window system and Brian Paul, which is the program that started the open source Mesa graphics library.

    • A check for the presence of WebGL can be done through:

      var canvas = document.createElement('canvas');
      var gl = canvas.getContext('webgl');
      
      var debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
      var vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
      var renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
      
      if(vendor == "Brian Paul" && renderer == "Mesa OffScreen") {
          console.log("Chrome headless detected");
      }
      
    • Not all Chrome headless will have the same values for vendor and renderer. Others keep values that could also be found on non headless version. However, Mesa Offscreen and Brian Paul indicates the presence of the headless version.

  • Browser features: Modernizr library enables to test if a wide range of HTML and CSS features are present in a browser. The only difference we found between Chrome and headless Chrome was that the latter did not have the hairline feature, which detects support for hidpi/retina hairlines.

    • A check for the presence of hairline feature can be done through:

      if(!Modernizr["hairline"]) {
          console.log("It may be Chrome headless");
      }
      
  • Missing image: The last on our list also seems to be the most robust, comes from the dimension of the image used by Chrome in case an image cannot be loaded. In case of a vanilla Chrome, the image has a width and height that depends on the zoom of the browser, but are different from zero. In a headless Chrome, the image has a width and an height equal to zero.

    • A check for the presence of Missing image can be done through:

      var body = document.getElementsByTagName("body")[0];
      var image = document.createElement("img");
      image.src = "http://iloveponeydotcom32188.jg";
      image.setAttribute("id", "fakeimage");
      body.appendChild(image);
      image.onerror = function(){
          if(image.width == 0 && image.height == 0) {
          console.log("Chrome headless detected");
          }
      }
      

These are some of the crucial factors why headless browsers are more prone to get detected.


Outro

  • Detecting PhantomJS Based Visitors
  • Unable to use Selenium to automate Chase site login
  • Selenium webdriver: Modifying navigator.webdriver flag to prevent selenium detection
Thursday, June 3, 2021
 
talkhabi
answered 5 Months ago
48

The error you are seeing says it all :

selenium.common.exceptions.SessionNotCreatedException: Message: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 ('There are no more files.') for URL 'http://localhost:65393/'

If you visit the Release Page of headless-selenium-for-win the Release Notes for headless-selenium-for-win v1.4 it clearly mentions the following :

  • Supporting Firefox and Chrome
  • Windows explorer is not started anymore in the headless desktop.
  • desktop_utils.exe learned to not run explorer.exe after a headless desktop is created.

Hence Internet Explorer can't be initialized with headless_ie_selenium.exe.


Update :

As per your comment Are there any alternatives to open IE and run it in background via selenium with mouse/keyboard inputs the straight Answer is No.

@JimEvans in the Github Thread Headless IE with selenium not working on Windows server clearly mentions that :

The IE driver does not support execution without an active, logged-in desktop session running. You'll need to take this up with the author of the solution you're using to achieve "headless" (scare quotes intentional) execution of IE.

He also adds :

Mouse and keyboard simulation won't work without an active session. It's a browser limitation, not a driver limitation.

Friday, August 6, 2021
 
nfechner
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share