0

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.

4
  • When you click by hand, you have to wait until the modal dialogue is dismissed before you can click again. But your loop isn't waiting, and you're clicking all the buttons at once, which it's not designed to handle. Commented Dec 18, 2024 at 19:01
  • @Barmar Thanks for the quick answer. Can you expound on that a little more? By indicating wait_element = data_bill[5].find_element(By.XPATH, './/div//span') before clicking on it, am I not selecting that single span to click on? I have also listed my four different attempts to wait for the page to load. Can you explain why those do not work for the modal dialogue and what I should be doing instead? Commented Dec 18, 2024 at 19:10
  • I'm talking about the for loop that clicks on that button in each row. Commented Dec 18, 2024 at 19:13
  • @Barmar I apologize, what I posted was missing some key information. I have updated it. I do need to click into each row and get data from the new screen from each row. But I do close out of each new screen after I get that data. Commented Dec 18, 2024 at 19:31

1 Answer 1

0

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.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.