我使用的是Selenium webdriver,登錄後無法與元素進行交互。這意味着元素交互在登錄屏幕中正常工作。Python硒不能與元素相互作用
該webdriver是HTMLUNITS。我不想使用另一個無頭驅動程序,因爲需要在Windows上運行此腳本,並且它是唯一允許我通過登錄屏幕的驅動程序。已經使用PhantomJS(沒有工作),並嘗試配置headless_chrome沒有成功。
的源代碼是在這裏: https://gist.github.com/anonymous/6edf78d63d698340b1ae53a597776037
的<input>
說我試着去互動是從源代碼行209。同樣的莫過於:
<input id="ToolbarOkCode" ct="I" lsdata="{0:'ToolbarOkCode',1:'Command',4:200,13:'150px',23:true}" lsevents="{Change:[{ClientAction:'none'},{type:'TOOLBARINPUTFIELD'}],Enter:[{ClientAction:'submit',PrepareScript:'return\x20its.XControlSubmit\x28\x29\x3b',ResponseData:'delta',TransportMethod:'partial'},{Submit:'X',type:'TOOLBARINPUTFIELD'}]}" type="text" maxlength="200" tabindex="0" ti="0" title="Command" class="urEdf2TxtRadius urEdf2TxtEnbl urEdfVAlign" value="SM37" autocomplete="on" autocorrect="off" name="ToolbarOkCode" style="width:150px;"/>
我需要寫一個值,然後按回車鍵即可提交form
。沒有任何「提交」button
。
嘗試這樣:
driver.find_element_by_id('ToolbarOkCode').send_keys('value')
driver.find_element_by_id('ToolbarOkCode').send_keys(Keys.ENTER)
沒有工作。該元素已找到,但「send_keys」操作不起作用。
2.使用JavaScript來填充輸入字段試過,做工精細:
driver.execute_script("document.getElementById('ToolbarOkCode').setAttribute('value', 'SM37')")
然後試着按ENTER鍵,相同的錯誤面前:
driver.find_element_by_id('ToolbarOkCode').send_keys(Keys.ENTER)
4.試圖發送一個submit()
事件,顯然有效,但表格完全沒有提交:
driver.find_element_by_id('ToolbarOkCode').submit()
TEST
也試圖與此:
12:12:11.233 INFO - Executing: [find element: By.xpath: //input[@id='ToolbarOkCode']])
12:12:11.432 INFO - Done: [find element: By.xpath: //input[@id='ToolbarOkCode']]
12:12:11.444 INFO - Executing: [send keys: 5 <input id="ToolbarOkCode" ct="I" lsdata="{0:'ToolbarOkCode',1:'Command',4:200,13:'150px',23:true}" lsevents="{Change:[{ClientAction:'none'},{type:'TOOLBARINPUTFIELD'}],Enter:[{ClientAction:'submit',PrepareScript:'return\x20its.XControlSubmit\x28\x29\x3b',ResponseData:'delta',TransportMethod:'partial'},{Submit:'X',type:'TOOLBARINPUTFIELD'}]}" type="text" maxlength="200" tabindex="0" ti="0" title="Command" class="urEdf2TxtRadius urEdf2TxtEnbl urEdfVAlign" value="" autocomplete="on" autocorrect="off" name="ToolbarOkCode" style="width:150px;" />, [S, M, 3, 7]])
12:12:12.718 WARN - Exception thrown======= EXCEPTION START ========
EcmaError: lineNumber=[1] column=[0] lineSource=[ function (oDomEvent) {] name=[TypeError] sourceName=[http://sapmig03.cge.cl:8010/sap/public/icmandir/its/ls/js/lightspeed.js?600#3(eval)] message=[TypeError: Cannot call method "setOpenerRef" of null (http://sapmig03.cge.cl:8010/sap/public/icmandir/its/ls/js/lightspeed.js?600#3(eval)#1)]com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot call method "setOpenerRef" of null (http://sapmig03.cge.cl:8010/sap/public/icmandir/its/ls/js/lightspeed.js?600#3(eval)#1)
任何想法:
driver.find_element_by_xpath("//input[@id='ToolbarOkCode']").send_keys("SM37")
driver.find_element_by_xpath("//input[@id='ToolbarOkCode']").send_keys(Keys.ENTER)
之前收到同樣的錯誤?
THanks提前!
你是否可以手動做到這一點? –
是的,它可以手動工作。 –