5

So, I have a Web application at work that need to gather information and build some reports and run some basic data analysis.

The thing is that I'm a complete newbie to HTML, Ajax (Asynchronous JavaScript and XML), Python and Selenium.

What I gather so far is this:

  1. Ajax nature is to perform asynchronous Web Browser activities and in my case, sending server requests to push/pull some data
  2. Selenium handles the asynchronous events performing Wait actions like:
    • time.sleep('time in ms') # using the time library. So not REALLY Selenium;
    • Explicit Waits: you define to wait for a certain condition to occur before proceeding further in the code;

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC

    delay_time = 10 # how much time until raises NoExeption in Selenium    

    driver = webdriver.Firefox()
    driver.get("http://somedomain/url_that_delays_loading")

    webDriverWait(driver,delay_time)\
    .until(EC.presence_of_element_located((By.ID, 'IdOfMyElement')))`

EC stands for expected conditions represented by:

title_is;

title_contains;

presence_of_element_located

visibility_of_element_located

visibility_of

presence_of_all_elements_located

text_to_be_present_in_element

text_to_be_present_in_element_value

frame_to_be_available_and_switch_to_it

invisibility_of_element_located

element_to_be_clickable

staleness_of

element_to_be_selected

element_located_to_be_selected

element_selection_state_to_be

element_located_selection_state_to_be

alert_is_present



  • Implicit Waits: tell WebDriver to poll the DOM (Document Object Model) for a certain amount of time when trying to find an element or elements if they are not immediately available; driver.implicitly_wait(10)-
  • Executing JavaScript using Java and applies wait: j Query keeps a count of how many Ajax calls are active in its query.active variable;
  • FluentWait: FluentWait option to handle uncertain waits;
  • WebdriverWait: use ExpectedCondition and WebDriverWait strategy.

What to use since I have the following situation:

Button to send a clear request via Ajax.

<div id="div_39_1_3" class="Button  CoachView CPP BPMHSectionChild CoachView_show" data-type="com.ibm.bpm.coach.Snapshot_b24acf10_7ca3_40fa_b73f_782cddfd48e6.Button" data-binding="local.clearButton" data-bindingtype="boolean" data-config="config175" data-viewid="GhostClear" data-eventid="boundaryEvent_42" data-ibmbpm-layoutpreview="horizontal" control-name="/GhostClear"> 
    <button class="btn btn-labeled"><span class="btn-label icon fa fa-times"></span>Clear</button></div>

This is the event of the button: function(a) {!e._instance.btn.disabled && c.ui.executeEventHandlingFunction(e, e._proto.EVT_ONCLICK) && (e._instance.multiClicks || (e._instance.btn.disabled = !0, f.add(e._instance.btn, "disabled")), e.context.binding && e.context.binding.set("value", !0), e.context.trigger(function(a) { e._instance.btn.disabled = !1; f.remove(e._instance.btn, "disabled"); setTimeout(function() { c.ui.executeEventHandlingFunction(e, e._proto.EVT_ONBOUNDARYEVT, a.status) }) }, { callBackForAll: !0 })) }

Then, my network informs that the ajaxCoach proceeds to the following requests

Networkflow for the clear button

Is it possible to selenium to see/find if an AJAX action concluded the page actualization action in Python?

5
  • Yes it's possible, but it depends on the library used by the page to perform the ajax requests. The idea is to wait for a status or for the count of pending requests to be 0. Commented Sep 15, 2017 at 15:22
  • @FlorentB., thank you for your reply. I tried to find something about counting the pending requests but found nothing either in Selenium or Ajax Js Scripting with it. Do you have an example on how to proceed with that? Commented Sep 15, 2017 at 15:54
  • an example is useless without knowing exactly how the page handles the requests. Add a break-point for the click and run the code step by step to find out which library is used. Commented Sep 15, 2017 at 16:07
  • @FlorentB.For more that I could gather (since I had to learn the main concepts of JS and it's library's, after some blackboxing and debugging, dojo.js (hope that some valid answer) is called in the stack and some interaction with some functions inside happen. Just could not find status or requests in the process. Commented Sep 15, 2017 at 17:25
  • You can check for an onloadend event in js. And execute a script to return that value into python. Commented Sep 17, 2017 at 12:02

1 Answer 1

1

if you have jquery on the page, you can define the button with jquery and wait until the event function is ready. for your question:

    driver.execute_script('button = $("#div_39_1_3");')
    events = driver.execute_script('return $._data(button[0], 
    "events");')

now you need to wait until events variable is not none.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.