Skip to content
This repository was archived by the owner on May 2, 2023. It is now read-only.

Commit b941b37

Browse files
committed
fix : element click intercepted
Have tested and it seems good, You only get the ElementClickInterceptedException when for example there's a div covering the input and it thinks it'll click the wrong thing- I did hpwver add a wait which should wait until it's there. General robustness.. Seems OK.
1 parent a4071ca commit b941b37

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

missionchief_bot.py

+29-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from selenium import webdriver
22
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+
37
import time
48
import platform
59
import os
@@ -271,16 +275,31 @@ def despatchVehicles(self,mission):
271275
logger.debug("Mission still needs vehicles, despatching.")
272276
print("Despatching " + ownedVehicle.getName() + " to " + mission.getName())
273277
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
284303
except (NoSuchElementException) as e:
285304
logger.error("Vehicle checkbox cannot be found, or clicked" + ownedVehicle.getID())
286305
continue

0 commit comments

Comments
 (0)