立ち上げ時にやること
タイムゾーンがズレているとサイト訪問時にタイムゾーン変更を促すポップアップが上がってきてSeleniumの動作が止まる。
そのため、Seleniumを動かすマシンでタイムゾーンの設定をしようとした。
かなり手こずったので備忘録を残す。
apt-upgradeを初手で行うとusrmergeがない、と言われハマる。
docker run -e TZ=Asia/Tokyo --rm -it -p 4444:4444 -p 5900:5900 -p 7900:7900 --shm-size 2g seleniarm/standalone-chromium:initimage sudo apt update sudo apt install python3-pip sudo apt install python3-selenium
忘れそうなので、これもメモ
VNCでブラウジング動作を確認する方法
Docker Seleniumのwebブラウザ操作を表示する。
5900ポートでVNCサーバに繋げられる。
Finderを開いて command + k
vnc://localhost:5900
XPATHでもCSS_Selectorでも選択できない要素のクリック
普通にクラスを指定してもダメ。
XPATHでもCSS_Selectorで指定してもクリックできない。
* driver.find_element(By.CLASS_NAME, "btn_close").click() * driver.find_elements(By.CSS_SELECTOR, “a[href*=“#”]”).click()
ずっとこんな感じの同じエラーが出てくる。
* selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: * selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable * AttributeError: 'list' object has no attribute 'click'
試行錯誤の末、マウスオーバーさせたらClickが成功した。
push = driver.find_element(By.CLASS_NAME, "btn_close") actions = ActionChains(driver) actions.move_to_element(push) actions.click() actions.perform() time.sleep(2)
さらに試行錯誤の末、こうなった。
push = driver.find_element(By.XPATH, "コピーしたxpath") actions = ActionChains(driver) actions.click(push).perform()
Docker Imageを保存する方法
docker ps docker commit --pause=false ttfb2dagaa0 seleniarm/standalone-chromium:hogehoge docker commit --[OPTION] [CONTAINER ID] [Repository:Tag]