I am trying to click on the below element using ChromeDriver .click(). It is one of the columns in a row of a table that contains bills.
<td onclick="ShowAdvancedTimeEntry(1,0,0,'276984899',0,generateRandom());return false;">TG</td>
Here is how I am trying to click on it in bare bones. I have also tried clicking right on the element with wait_element = data_bill[5].
bills_xpath = './/tr[@class="rowb"]'
bills = group.find_elements(By.XPATH, bills_xpath)
for j, bill in enumerate(bills):
data_bill = bill.find_elements(By.TAG_NAME, 'td')
wait_element = data_bill[5].find_element(By.XPATH, './/div//span')
wait_element.click()
for window in all_windows:
if window != original_window:
d.switch_to.window(window)
#get needed data from this window#
d.close()
d.switch_to.window(original_window)
When done manually, this pops up a new window with additional information about the bill represented by that row of data.
However, when using the ChromeDriver click, I am triggering the below dynamic error display in the HTML of the destination page:
<!-- ko if: false -->
<div id="refreshOverlay" class="timersRefreshing" style="z-index:1">
Loading...
</div>
<!-- /ko -->
<!-- #region TIMER -->
I am also getting these three errors which are not present when manually clicking the link.
screenshot of error messages
From what I have been able to gather, it seems like using the .click is causing errors in the jquery (maybe an Ajax call), but I am not familiar enough with jquery to get to the bottom of this. Does anyone know why these errors are happening or have more information about why Chromedriver .click functions differently than manually clicking?
I have tried setting the ChromeDriver options with the below commands:
chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.page_load_strategy = 'eager'
d = webdriver.Chrome(service=Service(executable_path=driver_path), options=chrome_options)
I have also tried various iterations of waiting for the page to load and the Ajax processes to complete. The page is loading successfully since what I am seeing is supposed to be displayed, but maybe the jquery functions aren’t being allowed time to finish?
wait = WebDriverWait(d, 15)
wait_element = data_bill[5].find_element(By.XPATH, './/div//span')
#wait.until(ec.element_to_be_clickable((By.XPATH,wait_element)))
is_ajax_complete = "return jQuery.active == 0" # This works for jQuery-based websites
wait.until(lambda d: d.execute_script(is_ajax_complete))
wait_element.click()
wait.until(lambda driver: driver.execute_script('return document.readyState') == 'complete')
wait.until(ec.presence_of_element_located((By.XPATH, '//*[@id="billableType"]/div[1]/label[1]/input')))
I made attempts at passing an authtoken and waiting for the element to be clickable but did not have much luck.
Trent Giffin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4
It was a cookie issue. The domain of the website I was using had changed between writing the code and adding this new functionality. The cookies were stored with the new domain, but the code was loaded a page with the old domain. It routed to the page, but then failed to load via on click because the website domain did not match the domain stored in the cookies.
Trent Giffin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.