class SlideUtils: @staticmethod def slide_by_action_chains(driver, degree): # 通过 JavaScript 执行鼠标事件 script = """ degree=arguments[0] function generateSmartTrajectory(targetX) { const trajectory = []; let x = 0; let t = 0; trajectory.push([x, 0, t]); while (x < targetX * 0.3) { const dx = Math.random() < 0.7 ? 1 : 2; x += dx; t = 12 + Math.floor(Math.random() * 10); // 12~22ms trajectory.push([x, 0, t]); } while (x < targetX - 8) { const dx = 2 + Math.floor(Math.random() * 3); // 起步步长2~4 x += dx; t = 10 + Math.floor(Math.random() * 8); // 停留10~18ms trajectory.push([x, 0, t]); } const overshoot = targetX + Math.floor(Math.random() * 7) + 3; // 2~4 px 超过 while (x < overshoot) { const dx = Math.random() < 0.8 ? 1 : 0; // 单次步长1为主 x += dx; t = 28 + Math.floor(Math.random() * 25); // 停留28~53ms trajectory.push([x, 0, t]); } while (x > targetX) { const dx = Math.random() < 0.6 ? -1 : 0; // 回退 x += dx; t = 50 + Math.floor(Math.random() * 40); // 停留50~90ms trajectory.push([x, 0, t]); } const lingerCount = 2 + Math.floor(Math.random() * 3); // 结束 2~4 次 for (let i = 0; i < lingerCount; i++) { t = 100 + Math.floor(Math.random() * 250); // 停留100~350ms trajectory.push([targetX, 0, t]); } return trajectory; } async function jdRotate_slide(trajectory) { const element = document.querySelector('#slider-div'); coordinates = element.getBoundingClientRect(); console.log(coordinates) centerX = coordinates.x + 10 centerY = coordinates.y + 10 const mouseEvent = (type, x, y) => { const event = new MouseEvent(type,{ bubbles: true, cancelable: true, clientX: x, clientY: y, }); element.dispatchEvent(event); } ; mouseEvent('mousedown', centerX, centerY); let y = 0 for (let i = 1; i < trajectory.length; i++) { [x,k,t] = trajectory[i]; y = y + Math.floor(Math.random() * 2); mouseEvent('mousemove', centerX + x, centerY + y); await new Promise(resolve => setTimeout(resolve, t)); } mouseEvent('mouseup', centerX + x, centerY + y); } x =degree/1.5 track_ = generateSmartTrajectory(x) jdRotate_slide(track_) """ driver.execute_script(script, degree)