38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import time
|
|
|
|
from selenium import webdriver
|
|
from selenium.webdriver.chrome.options import Options
|
|
from selenium.webdriver.common.keys import Keys
|
|
|
|
|
|
options = Options()
|
|
options.add_experimental_option("debuggerAddress", os.environ.get("WEHAGO_CHROME_DEBUGGER_ADDRESS", "127.0.0.1:9225"))
|
|
driver = webdriver.Chrome(options=options)
|
|
|
|
try:
|
|
webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
|
|
clicked = driver.execute_script(
|
|
"""
|
|
const width = window.innerWidth;
|
|
const candidates = Array.from(document.querySelectorAll('button, a, div, span'))
|
|
.filter(el => (el.textContent || '').trim() === '조회')
|
|
.filter(el => {
|
|
const r = el.getBoundingClientRect();
|
|
const style = getComputedStyle(el);
|
|
return r.width > 0 && r.height > 0 && r.top >= 70 && r.top <= 240
|
|
&& r.left > width * 0.6 && style.display !== 'none' && style.visibility !== 'hidden';
|
|
})
|
|
.sort((a, b) => b.getBoundingClientRect().left - a.getBoundingClientRect().left);
|
|
if (!candidates.length) return false;
|
|
candidates[0].click();
|
|
return true;
|
|
"""
|
|
)
|
|
print(f"query_clicked={bool(clicked)}", flush=True)
|
|
time.sleep(4)
|
|
finally:
|
|
driver.quit()
|