Closed mohesham88 closed 9 months ago
def play(driver: webdriver.Chrome, wait: WebDriverWait, engine: stockfish.Stockfish, move): t_ = time() engine.make_moves_from_current_position([move]) pos0 = move[:2] pos1 = move[2:] pos0 = C.square + str(C.let_to_num[pos0[0]]) + pos0[1] pos1 = C.square + str(C.let_to_num[pos1[0]]) + pos1[1] cls = C.space.join([C.piece, pos1, C.white_pawn, C.some_id]) scr_rm = C.js_rm_ptr % (C.board, C.some_id) scr_add = C.js_add_ptr % (C.board, cls) driver.execute_script(scr_rm) driver.execute_script(scr_add) e0 = wait.until(EC.element_to_be_clickable((By.CLASS_NAME, pos0))) e0.click() e1 = wait.until(EC.element_to_be_clickable((By.CLASS_NAME, C.some_id))) e1.click() driver.execute_script(scr_rm) w = WebDriverWait(driver, 0.05) try: window = w.until(EC.visibility_of_element_located((By.CLASS_NAME, C.promotion_window))) sleep(0.2) items = window.find_elements(By.CLASS_NAME, C.black_queen) if len(items) == 0: items = window.find_elements(By.CLASS_NAME, C.white_queen) items[0].click() except selenium.common.exceptions.TimeoutException: pass
Here, we're using WebElement.find_elements(By, selector) to find a clickable element, which is a Selenium-specific solution. As far as I know, Selenium cannot be used to implement chrome extension's logic. Therefore I would consider using pure JavaScript or a CRX-specific solution instead.
Sorry I couldn't find any other way to contact you I'm making a chrome extension bot for chess.com also however im struggling to move the pieces i couldn't find the dom element that has the event listeners for clicking the piece in order to move it I've tried all elements that have the mousedown, click (the board included)event listeners but couldn't make it Can you explain me to me how did you move the pieces i'm not familiar with selenium Thank you moheshamfathi@gmail.com