前提・実現したいこと
現在職場で利用しているグループウェア「GroupSession」へpythonで自動ログインを行い、
ログイン後のトップページで「業務開始」ボタンを押下するというプログラムを作ろうとしています。
◆環境、使用モジュール
windows10
python 3.7.1
selenium 3.141.0
chrome 70.0.3538.110
chromedriver 2.44
発生している問題・エラーメッセージ
自動ログインの部分までは成功したのですが、ログイン後に表示されたトップページにおいて
目的の業務開始ボタンをクリックすることが出来ていない状況です。
以下が実際のコードとなります。
Python
1import json 2from bs4 import BeautifulSoup 3from time import sleep 4from selenium import webdriver 5from selenium.webdriver.chrome.options import Options 6from selenium.webdriver.common.keys import Keys 7 8config_file = open('config.json' , 'r' , encoding="utf-8_sig") 9config = json.load(config_file) 10 11URL = config["GS_LOGIN_URL"] 12ID = config["GS_LOGIN_ID"] 13PASS = config["GS_LOGIN_PASS"] 14 15options = Options() 16options.set_headless(True) 17driver = webdriver.Chrome(chrome_options=options) 18driver.get(URL) 19sleep(3) 20 21driver.find_element_by_name("cmn001Userid").send_keys(ID) 22driver.find_element_by_name("cmn001Userid").send_keys(Keys.TAB) 23driver.find_element_by_name("cmn001Passwd").send_keys(PASS) 24driver.find_element_by_name("cmn001Passwd").send_keys(Keys.ENTER) 25sleep(5) 26 27driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") 28driver.find_element_by_css_selector("#timecard_tcdmain > form > table > tbody > tr:nth-child(2) > td.td_type1 > table > tbody > tr:nth-child(1) > td > input").click 29
実行すると最終行のコードにてそんなエレメントは存在しないという内容の
エラーが返されてきます。
(css selectorはchromeのデベロッパーツールからcopy selectorにて取得したものです。)
ログイン後のページを確認するためにBeautifulSoupをインポートし
printしてみたところ、ログイン後のページのhtmlではあるのですが
下記のようなアローが全て閉じられた骨組みの部分だけのhtmlが取得されてきてしまいます。
HTML
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2<html xmlns="http://www.w3.org/1999/xhtml"><head> 3<title>[GroupSession]</title> 4<link href="../common/images/favicon.ico" rel="SHORTCUT ICON"/> 5<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/> 6<link href="../common/css/theme1/theme.css?480" rel="stylesheet" type="text/css"/> 7<link href="../common/css/default.css?480" rel="stylesheet" type="text/css"/> 8</head> 9<frameset cols="1" frameborder="no" rows="90,*"> 10<frame name="menu" noresize="true" scrolling="no" src="../common/cmn003.do?menuPage=1"/> 11<frame name="body" scrolling="yes" src="../main/man001.do"/> 12</frameset> 13<noframes> 14Group Sessionはフレーム対応のブラウザでなければご利用いただけません。 15</noframes> 16</html>
質問したいこと
上記を踏まえて以下の二点について質問させて頂きたいです。
◆htmlが正しく取得できていないのはなぜでしょうか
◆htmlがうまく取得できていないことが原因で業務開始ボタンを探し出すことが出来ていないのか、
そもそもcssselectorの設定が誤っているのか
回答2件
あなたの回答
tips
プレビュー