-1

I want to click a button after an image is visible/ loaded, the test takes 10 min to run with Chrome Vs 0:00:00.029671 with firefox. It's too slow , i'd rather be running test manually. How can i have the same time execution ? i'm desperate , taking me days ...with multiple code solution from internet

I upgrade google Chrome 75.0.3770.90 and ChromeDriver
I added some options to run chrome :(not very helpful in this case)
      options.add_argument('--no-sandbox')  
      options.add_argument('--disable-gpu')  
      options.add_argument('start-maximized') 
      options.add_argument('disable-infobars')
      options.add_argument("--disable-extensions")

connectionStatus = True

while connectionStatus == True:
    try:
        WebDriverWait(conn.driver, 10).until(ec.visibility_of_element_located(
            (By.CSS_SELECTOR, "img[src='../public/images//disconnect.png']")))
        element = conn.driver.find_element(By.CSS_SELECTOR, 'img[src="../public/images//disconnect.png"]')
        element.is_displayed

        print("disconnect")
        connectionStatus = False
    except NoSuchElementException as e:
        print("Waiting for M to disconnect from VW")
        time.sleep(10)
    except TimeoutException:
        print("TIMEOUT - Element not found: ")

    conn.driver.find_element(By.CSS_SELECTOR, "#btnSendUpd").click()

Execution:

Start:  2019-06-18 16:13:06.710734
TIMEOUT - Element not found: 
Diff =  0:05:00.004450
disconnect
Diff =  0:05:00.046355


NB: the code html contains only css , not ID to use findElementById

Windows 10 - 64bits(I use chromedriver 32bits-they say that is working on 64bits)
Selenium 3.141.0
Miya
  • 41
  • 6
  • try to use "headless" mode in Chrome – Adi Ohana Jun 17 '19 at 12:45
  • I was looking for this method , but it seems that runs tests without a graphical interface, which i must have to present my project :( thank for your answer. – Miya Jun 17 '19 at 14:02
  • "0:00:00.029671" You are suggesting that it takes less than a millisecond to run in Firefox? The only way that is happening if it is erring out quickly... Add a "catch all the rest" exception handler to that to make sure you don't miss anything. And, it doesn't look like the code would take 10 minutes. Whatever it is waiting for takes 10 minutes. So why are you hoping to fix that via the Selenium script? I think we are missing important information here. – Asyranok Jun 17 '19 at 16:57
  • Additionally to my last comment. There are issues with Chromedriver where if you use the wrong driver, 32 bit vs 64 bit, execution is slowed down by several hundred percent. You would most notice this if you try to tell the driver to enter some text. `SendKeys("A long enough string")`. Each character would type one at a time, with about 10 seconds in between each character. But I still don't see how the above script takes 10 minutes to run. It is entirely dependent on the thing that it is waiting for on the DOM. – Asyranok Jun 17 '19 at 17:03
  • Could be pageload timeout at play. Post your URL.get.... and anything that sets the pageload timeout, if you do that... I think the defaults will be different in geckodriver and in chromedriver. – pcalkins Jun 17 '19 at 19:10
  • @Asyranok i had that problem (execution too slow with sendKeys) with IE when i used IEServerDriver 64bits, luckily resolved with driver 32bits. for chrome : i added the "catch all the rest" doesn't help, i removed every line one by one to see Whatever it is waiting for takes 10 minutes, but same results , I don't understand, the img i'm waiting for... is charged with javascript , May be chrome does not interpret the same way as firefox ????chrome is supposed to be the fastest with fewer pblms – Miya Jun 19 '19 at 06:30
  • @pcalkins : the loading of the page is done well, my image is loaded, we see it visually, (it is not the first page loaded), and I already used "WebDriverWait(conn.driver, 10).until(ec.visibility_of_element_located" in other pages without pblm – Miya Jun 19 '19 at 06:30
  • expected condition will throw the timeout if the xpath doesn't match... maybe you're in a loop there... this XPATH seems wrong: "img[src='../public/images//disconnect.png']" maybe try: "img[@src='../public/images//disconnect.png']" – pcalkins Jun 19 '19 at 16:57
  • also be sure to add connectionStatus = False to the catch for timeout. The other catch for no such element is not necessary... your expected wait ignores that. It will only throw timeout – pcalkins Jun 19 '19 at 18:21
  • @pcalkins : the Xpath is correct , it's found after all (after 10 min too long) thanks for ur advice , i removed the "except NoSuchElementException as e" it causesTimeout like you said – Miya Jun 20 '19 at 10:39

1 Answers1

1

I was told that the website i'm testing works with Hidden Iframe (Comet Programming with Javascript), A basic technique for dynamic web application is to use a hidden iframe HTML element (an inline frame, which allows a website to embed one HTML document inside another). This invisible iframe is sent as a chunked block, which implicitly declares it as infinitely long (sometimes called "forever frame")

I checked "development tool"=> Network : it's like the script never stop F12-Network-Chrome, and i think that Chrome is waiting for it to finish, that's why he is too long (Firefox doesn't)

As a workaround i added this line to force chrome to not wait page loading too long :

driver.set_page_load_timeout(7)

Execution now takes seconds:

Start:  2019-06-20 13:23:24.746351  
TIMEOUT - Element not found    
Diff =  0:00:07.004282    
disconnect    
Diff =  0:00:07.036196
Miya
  • 41
  • 6
  • I thought it might be something like this. There are certain scripts/plugins that constantly poll for things like mouse or keyboard actions too. (For collecting data on usability...) I know this can sometimes cause endless loading, too. – pcalkins Jun 20 '19 at 16:10
  • @pcalkins: thanks for ur feedback ....now with this workaround I have another problem where I block another page that contains a progress bar to fully load... any ideas that can help? – Miya Jun 24 '19 at 06:54
  • hard to say without looking at the markup. I'm still a little surprised that Chromedriver and Geckodriver are acting differently here. If the pageload event never fires other scripts on that page may have problems... and Selenium itself may have trouble injecting itself into the page. It looks like the pageload timeout is throwing here, not the expected condition. (else you'd have 17 seconds not 7) The pageload setting is global. – pcalkins Jun 24 '19 at 18:35
  • maybe try using javascriptexecutor to send "window.stop();" Not sure if that'll help and it's not supported in IE. Now that I think of it, the problem might not be that pageload event never fires, but that the endlessly loading frame is firing it over and over.... you might want to debug the scripts on that page to check for pageload or ready state events. – pcalkins Jun 24 '19 at 19:16
  • they may be able to fix this by ensuring that the iframe is only loaded AFTER pageload. – pcalkins Jun 24 '19 at 19:21
  • maybe try setting "pageloadstrategy" in Chromedriver to "none". I've never used this before, and I'm not sure exactly what happens when Selenium doesn't wait for pageload event. There's further discussion here: https://stackoverflow.com/questions/44770796/how-to-make-selenium-not-wait-till-full-page-load-which-has-a-slow-script/44771628#44771628 – pcalkins Jun 24 '19 at 21:49