al3xkras / chess-com-bot-selenium

Chess.com bot (Docker-Selenium)
9 stars 3 forks source link

Timeout Problem #8

Closed mark-baumann closed 3 hours ago

mark-baumann commented 1 month ago

Hey Alex,

i installed your script on my Windows Machine. The first move works without problem, but then I will get this error Message:

(main.py:573)←[0m ←[0m2024-07-17 11:37:52 ←[32m[INFO] [←[32mchess-log,←[32m main.py:407]←[0m←[38;20m: Board: <selenium.webdriver.remote.webelement.WebElement (session="dc029f43251280d13b91a861176a20cc", element="f.0EC23E972DB1C283AADEEC4C3844C71E.d.EDFE93657D922298F600B4983D78FD9C.e.128")>←[0m ←[0m2024-07-17 11:37:52 ←[32m[INFO] [←[32mchess-log,←[32m main.py:419]←[0m←[38;20m: Is playing black pieces: False←[0m ←[0m2024-07-17 11:37:52 ←[33;20m[DEBUG]←[36m [chess-log,←[36m main.py:215]:←[0m←[38;20m <play> call took 0.000000s←[0m ←[31;20m 2024-07-17 11:37:54 [chess-log]: Traceback (most recent call last): File "C:\Users\mark\Desktop\chess-com-bot\main.py", line 565, in loop return await actions(engine, driver) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\mark\Desktop\chess-com-bot\main.py", line 457, in actions await play(driver_, engine, mv_) File "C:\Users\mark\Desktop\chess-com-bot\main.py", line 380, in play raise e File "C:\Users\mark\Desktop\chess-com-bot\main.py", line 368, in play await wait_until(driver, C.wait_2s, find_element_and_click( File "C:\Users\mark\Desktop\chess-com-bot\main.py", line 238, in wait_until return await CustomTask( ^^^^^^^^^^^^^^^^^ File "C:\Users\mark\Desktop\chess-com-bot\main.py", line 236, in wait_until_sub return WebDriverWait(drv_, delay_).until(condition_) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\mark\Desktop\chess-com-bot\venv\Lib\site-packages\selenium\webdriver\support\wait.py", line 105, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:

How can I solve this?

Kind regards Mark

al3xkras commented 1 month ago

Hi Mark,

Normally, when the error occurs at "line 368, in play await wait_until(driver, C.wait_2s, find_element_and_click(...)", the bot should reload the page if game controls are visible and --next-game-auto is set to True. Otherwise the bot will raise TimeoutException and start a new game (or more specifically, treat an existing game as if it was a new game).

To solve this error I ended up reloading the page entirely, as more optimal solutions didn't seem to work. I think, that it might have been related to the selenium backend, which is sometimes unable to locate dynamically added elements.

I have implemented a possible solution on the test branch, by changing the logic of when the page should be reloaded. This should help avoiding situations, where Selenium does not recognise the first dynamically added element.

To check if it works for you, clone the test branch:

git clone -b test --depth 1 https://github.com/al3xkras/chess-com-bot-selenium chess-com-bot-test

If the last commit did not solve the issue, I might additionally require the following information:

Kind regards, Alexander

mark-baumann commented 1 month ago

Worked at Test Branch! Thank you for the awesome script!

Is it possible to make pull requests at this project or do you want to develop it by your own?

mark-baumann commented 1 month ago

If I play agains Computer without account there is no problem. If I play online with account, only the first move makes the programm.

I did not change anything in config. It is the same as you have. The error occur everytime when playing online

mark-baumann commented 1 month ago

←[31;20m 2024-07-18 17:49:54 [chess-log]: Traceback (most recent call last): File "C:\Users\mark\Desktop\chess-com-bot-test\main.py", line 572, in loop return await actions(engine, driver) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\mark\Desktop\chess-com-bot-test\main.py", line 470, in actions engine.make_moves_from_current_position(["".join(get_last_move(driver_))]) File "C:\Users\mark\Desktop\chess-com-bot-test\venv\Lib\site-packages\stockfish\models.py", line 238, in make_moves_from_current_position raise ValueError(f"Cannot make move: {move}") ValueError: Cannot make move: f1d3

al3xkras commented 1 month ago

If I play agains Computer without account there is no problem. If I play online with account, only the first move makes the programm.

I did not change anything in config. It is the same as you have. The error occur everytime when playing online

If the config was not modified, perhaps there is either something wrong with the selenium / chrome(chromium) support on your system, or the webdriver is not able to locate some elements due to modified settings on the chess.com website.

Could you record a short clip including the log outputs and chess.com page contents?

Is it possible to make pull requests at this project or do you want to develop it by your own?

A pull request solving this or any other issues will be appreciated.

ValueError: Cannot make move: f1d3

Obviously, I cannot guarantee a stable support on all environments, except for well-defined environments for which the bot was tested (particularly: the docker environment, specified in the docker-compose). I haven't encountered this error recently, after testing the bot for about 1 day, but it has occurred in the past before some fixes were applied

mark-baumann commented 1 month ago

(main.py:573)←[0m ←[0m2024-07-20 11:30:15 ←[32m[INFO] [←[32mchess-log,←[32m main.py:407]←[0m←[38;20m: Board: <selenium.webdriver.remote.webelement.WebElement (session="1d90bf39b2b15f1ccabe720d83b3d1fb", element="f.CB4413C1D2E43392BD7BAC28FDA15FB0.d.D3A41D3B5BBF83E44613D6AA916FEA1B.e.496")>←[0m ←[0m2024-07-20 11:30:15 ←[32m[INFO] [←[32mchess-log,←[32m main.py:419]←[0m←[38;20m: Is playing black pieces: False←[0m ←[0m2024-07-20 11:30:15 ←[33;20m[DEBUG]←[36m [chess-log,←[36m main.py:215]:←[0m←[38;20m <play> call took 0.000000s←[0m ←[31;20m 2024-07-20 11:30:17 [chess-log]: Traceback (most recent call last): File "C:\Users\Konta\OneDrive\Desktop\chess-bot\main.py", line 565, in loop return await actions(engine, driver) File "C:\Users\Konta\OneDrive\Desktop\chess-bot\main.py", line 457, in actions await play(driver_, engine, mv_) File "C:\Users\Konta\OneDrive\Desktop\chess-bot\main.py", line 380, in play raise e File "C:\Users\Konta\OneDrive\Desktop\chess-bot\main.py", line 368, in play await wait_until(driver, C.wait_2s, find_element_and_click( File "C:\Users\Konta\OneDrive\Desktop\chess-bot\main.py", line 238, in wait_until return await CustomTask( File "C:\Users\Konta\OneDrive\Desktop\chess-bot\main.py", line 236, in wait_until_sub return WebDriverWait(drv_, delay_).until(condition_) File "C:\Users\Konta\OneDrive\Desktop\chess-bot\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 105, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:

mark-baumann commented 1 month ago

is this feature only available for local chess.com Bot or also against real persons? It only works agains bots

al3xkras commented 1 month ago

supposed to work for both computer and real opponents