|
1 | 1 | from selenium import webdriver
|
2 | 2 | from selenium.common.exceptions import NoSuchElementException,ElementClickInterceptedException
|
| 3 | +from selenium.webdriver.common.by import By |
| 4 | +from selenium.webdriver.support.ui import WebDriverWait |
| 5 | +from selenium.webdriver.support import expected_conditions as EC |
| 6 | + |
3 | 7 | import time
|
4 | 8 | import platform
|
5 | 9 | import os
|
@@ -271,16 +275,31 @@ def despatchVehicles(self,mission):
|
271 | 275 | logger.debug("Mission still needs vehicles, despatching.")
|
272 | 276 | print("Despatching " + ownedVehicle.getName() + " to " + mission.getName())
|
273 | 277 | try:
|
274 |
| - logger.debug("Finding vehicle's checkbox") |
275 |
| - checkbox = browser.find_element_by_xpath('//input[contains(@id, '+ownedVehicle.getID() +')]') |
276 |
| - # Scroll the element |
277 |
| - browser.execute_script("arguments[0].scrollIntoView();", checkbox) |
278 |
| - checkbox.click() |
279 |
| - checkedunits = True |
280 |
| - des+=1 |
281 |
| - logger.debug("Adding vehicle to despatched list, and setting it as despatched") |
282 |
| - despatchedVehicles.append(ownedVehicle.getID()) |
283 |
| - ownedVehicle.setDespatched() |
| 278 | + logger.debug("Finding vehicle's checkbox" + ownedVehicle.getID()) |
| 279 | + # Confirm element exists |
| 280 | + if browser.find_element_by_xpath('//input[contains(@id, '+ownedVehicle.getID() +')]'): |
| 281 | + logger.debug("There is a checkbox with the id "+ownedVehicle.getID() ) |
| 282 | + checkbox = browser.find_element_by_xpath('//input[contains(@id, '+ownedVehicle.getID() +')]') |
| 283 | + wait = WebDriverWait(browser, 60) |
| 284 | + obj = wait.until(EC.presence_of_element_located((By.XPATH, '//input[contains(@id, '+ownedVehicle.getID() +')]'))) |
| 285 | + # Scroll to the element |
| 286 | + browser.execute_script("return arguments[0].scrollIntoView();", checkbox) |
| 287 | + logger.debug("Attempting to click " + ownedVehicle.getID()) |
| 288 | + try: |
| 289 | + checkbox.click() |
| 290 | + logger.debug(ownedVehicle.getID() + " was clicked") |
| 291 | + checkedunits = True |
| 292 | + des+=1 |
| 293 | + logger.debug("Adding vehicle to despatched list, and setting it as despatched") |
| 294 | + despatchedVehicles.append(ownedVehicle.getID()) |
| 295 | + ownedVehicle.setDespatched() |
| 296 | + except ElementClickInterceptedException as e: |
| 297 | + # Throws if it cant click the checkbox, as element is covering etc. Just continue. |
| 298 | + logger.debug(ownedVehicle.getID() + " was not clicked error ") |
| 299 | + continue |
| 300 | + else: |
| 301 | + logger.debug(ownedVehicle.getID() + " could not find checkbox at all- skipping ") |
| 302 | + continue |
284 | 303 | except (NoSuchElementException) as e:
|
285 | 304 | logger.error("Vehicle checkbox cannot be found, or clicked" + ownedVehicle.getID())
|
286 | 305 | continue
|
|
0 commit comments