2

Selenium::WebDriver::Error::ElementNotVisibleError: element not visible while calling send_key function when Chrome browser is used.

Selenium::WebDriver::Error::ElementNotVisibleError: element not visible

I'm running a ruby selenium script in parallel and facing the following issue while sending a text input through send_key to a webpage.

Im using following versions:
(Session info: chrome=43.0.2357.125)
(Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Linux 3.2.0-29-generic x86_64)

Following is a snippet of my code:

class MyClass
dir="xyz"
 @headless = Headless.new(display: 100, reuse: true, destroy_at_exit: false).start
Selenium::WebDriver::Chrome.driver_path = "/home/ubuntu/chromedriver"
    @driver = Selenium::WebDriver.for :chrome, :switches => %W[--ignore-certificate-errors --enable-logging --user-data-dir=#{dir} --disable-popup-blocking --disable-translate --use-fake-ui-for-media-stream --use-file-for-fake-audio-capture=song.wav --use-file-for-fake-video-capture=city_cif_15fps.y4m --use-fake-device-for-media-stream]
 @driver.get(@base_url + "/#{$url}/")
      wait = Selenium::WebDriver::Wait.new(:timeout => 90) # seconds
      wait.until {
        @driver.find_element(:id, "join-dialog-join")}
      x=@driver.find_element(:id, "join-dialog-input-name")
      @driver.execute_script("document.getElementById('join-dialog-input-name').style.visibility='visible';")
      @driver.execute_script("document.getElementById('join-dialog-input-name').removeAttribute('hidden');")
      #@driver.save_screenshot("Join-display_login_#{DateTime.now.to_s}_1_#{$epname}.png")
      #puts x.attribute("innerHTML")
      @driver.find_element(:id, "join-dialog-input-name").send_key "#{$epname}"
end

Ive tried making the element visible, also i tried remove attribute hidden if it happens to be so. Ive also tried using JS instead of send_keys but didnt seem to help.

@driver.execute_script("document.getElementById('join-dialog-input-name').value='Nikhil';")

Any help will be appreciated!!.

Is Xvfb causing this? Following is suggested by Console logs

[5245:5245:0626/181715:ERROR:chrome_browser_main_extra_parts_x11.cc(56)] X IO error received (X server probably went away)
[5280:5280:0626/181715:ERROR:x11_util.cc(82)] X IO error received (X server probably went away)

NOTE: This issue happens only when i start the script parallely.

HTML Snippet:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" class="snowy " lang="en"><head>

<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <!-- , maximum-scale=1.0 -->
<meta name="robots" content="noindex, nofollow" />
<!-- N.B.: 'IE=edge' must be the first, else it may be ignored -->
<!-- 'IE=edge' forces users out of compatibility/IE7 mode, even when in intranet -->
<!-- 'requiresActiveX=true' alerts users on IE10 metro mode that they need to switch back to IE32 -->
<!-- 'chrome=1' for chromeframe compatibility -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,requiresActiveX=true,chrome=1" />
<!-- <meta http-equiv="X-UA-Compatible" content="IE=Edge" />  -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<body class="gradient">

<div id="join-dialog" class="input-text" style="display: none;">
    <div class="dialog-header guest-flow">
        <div class="text-blue">
            <div class="proxima-bold text-25">Welcome.</div>
            <div class="proxima-light text-25">Please tell us who you are.</div>
        </div>
    </div>


    <div id="join-dialog-content">
        <!-- Guest workflow -->
        <div class="guest-flow" style="display: none;">
            <div class="field-wrapper">
                <input id="join-dialog-input-name" type="text" maxlength="50" placeholder="Enter your Name" rel="Enter your Name" value="" class="applytitle clearfocus" tabindex="1" aria-label="Enter Your Name" /><!-- _cato_ -->
                <div id="guest-name-error" class="error" style="display: none;">
                    Please enter a valid name.
                </div>
            </div>
            <div class="guest-email" style="display: none;">
                <div class="field-wrapper">
                    <input id="join-dialog-input-email" type="text" maxlength="70" value="" class="applytitle clearfocus" tabindex="2" aria-label="Enter your email address" /><!-- _cato_ -->
                    <div id="guest-email-error" class="error" style="display: none;">
                        Please enter a valid email address.
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
</body></html>
Nikhil
  • 43
  • 5
  • Changing the visibility of the one element might not be sufficient. It could be one of the ancestor elements that is not visible. Try iterating up the DOM and checking if any of them are also not `displayed?`. As well, sharing enough HTML to reproduce the problem would help. – Justin Ko Jun 26 '15 at 15:07
  • @justin I've updated the HTML. I noticed that 'display: none' was there in few of the ancestor elements which i tried changing to 'display: block' via JS but that also didn't seem to help. @driver.execute_script("document.getElementById('join-dialog-input-name').parentNode.style.display='block'") – Nikhil Jun 26 '15 at 19:24

1 Answers1

0

I think the problem is that the Element is really not visible in the default viewbox of Chrome. (And it can not be made visible in the default window size)

To Setup the the window size by webdriver you can do some thing like browser.manage().window().setSize(1200,1100); (this is under javascript. I think it looks similar under ruby)

When you are using chrome (since V59) in headless mode without Xvfb. See also this post https://stackoverflow.com/a/46299332/2718002

powerpete
  • 2,663
  • 2
  • 23
  • 49