The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

mancocapac (15) [Avatar] Offline
#1
It works fine until I get to the xvfb part.
When I run the script I get: "Element is not currently visible" for the "searchselector", same selector worked in the X11 part of TECH58. I thought it was a page/element load issue so I put in WebDriverWait until presence_of_element_located, it seems the element is present but not visible. I also tried visibility_of_element_located, but it does not pass this. I upped the time out to 100 secs.

The same script runs when I use the X11 style command line (see below)

docker run --rm -v $(pwd):/mnt selenium sh -c "xvfb-run -s '-screen 0 1024x768x24 -extension RANDR'\
> python /mnt/myscript.py"
Visiting github
Performing search
Traceback (most recent call last):
  File "/mnt/myscript.py", line 8, in <module>
    searchbox.send_keys('docker-in-practice\n')
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 322, in send_keys
    self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': keys_to_typing(value)})
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 457, in _execute
    return self._parent.execute(command, params)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 233, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
Stacktrace:
    at fxdriver.preconditions.visible (file:///tmp/tmpbGp3_A/extensions/fxdriver@googlecode.com/components/command-processor.js:10092)
    at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmpbGp3_A/extensions/fxdriver@googlecode.com/components/command-processor.js:12644)
    at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpbGp3_A/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
    at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpbGp3_A/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
    at DelayedCommand.prototype.execute/< (file:///tmp/tmpbGp3_A/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)

It works when I do this:
#!/bin/bash
docker run -e DISPLAY=$DISPLAY \
  -v /tmp/.X11-unix:/tmp/.X11-unix \
  --hostname=$HOSTNAME \
  -v $HOME/.Xauthority:/root/.Xauthority \
  -v $(pwd):/mnt \
  -it selenium bash

<on-the-container>$ python /mnt/myscript.py

mancocapac (15) [Avatar] Offline
#2
has anybody run this example? I'm wondering if there is something I am doing incorrectly, as I am new to docker and I don't know python.
like I said above, the same script runs successfully with X11, but gets hung up with xvfb
- thanks
mancocapac (15) [Avatar] Offline
#3
see: An element can't be clicked when the browser controlled by Selenium is displayed through xvfb #5828
https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/5828

add the following line

from selenium import webdriver
b = webdriver.Firefox()
b.set_window_size(1024, 768)    ### Add this line, Must match  command line for xvfb screen


xvfb-run -s '-screen 0 1024x768x24 -extension RANDR'


please update code sample
aidanhs (25) [Avatar] Offline
#4
Hi mancocapac, thanks for the detailed investigation and the fix

Unfortunately, I'm unable to check this right now as a recent firefox update in the Ubuntu repositories has broken selenium entirely (https://github.com/SeleniumHQ/selenium/issues/2110).

For when the fixed firefox is released, can you confirm you were using an Ubuntu 14.04 image? I tested this technique on multiple computers, so I'm a little surprise that it's broken! Such is the price of progress I suppose.

Aidan