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:
Wait
actions like:
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
driver.implicitly_wait(10)
-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
Is it possible to selenium to see/find if an AJAX action concluded the page actualization action in Python?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With