我的Selenium脚本运行良好,直到今天,最后一次使用是几天前。尝试运行脚本时,由于该版本不兼容,我不得不将ChromDriver更新为78.0.3904.70。我猜是因为我的Chrome已更新(?)。
替换chromedriver.exe之后,我尝试重新运行脚本。令人惊讶的是,一个InvalidArgumentException到达了。我该如何解决?
码:
upload = browser.find_element_by_xpath("//html[@class=' no-touch']//body//div[@id='page-wrapper']//div[@class='l-page']//section//form[@id='syi-form']//div[@id='photo-upload']//div[@class='box-content']//div[@class='upload-wrapper']//div[@id='uploaders']//div[@id='uploader-container-0']//div[@id]//input[@id]")
print(upload) #Test if item is found
upload.click()
错误:
<selenium.webdriver.remote.webelement.WebElement (session="a6af1cef2fb4a6fc81afeb10b9f9ad38", element="9bfb730f-984c-48d0-b5eb-077489f3a617")>
Traceback (most recent call last):
File "F:\Studie\Selenium\marktplaats.py", line 72, in <module>
upload.click()
File "C:\Users\Remco\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\Remco\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\Remco\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Remco\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
(Session info: chrome=78.0.3904.87)
元素:
<div id="uploaders" class="uploaders" data-image-urls="" data-image-ids=""><div id="uploader-container-0" class="uploader-container small empty uploader-container--gray" data-uploader-index="0" style="position: relative;">
<div id="file-picker-0" class="uploader-box small" style="z-index: 1;">
<div class="thumb">
<div class="uploader-overlay">
<span class="photo-action edit-action" title="Foto aanpassen">
<span class="mp-Icon-circle"><span class="mp-Icon mp-svg-edit photo-action-icon"></span></span>
</span>
<span class="remove photo-action" title="Foto verwijderen">
<span class="mp-Icon-circle"><span class="mp-Icon mp-svg-delete photo-action-icon"></span></span>
</span>
</div>
</div>
<div class="content">
<div class="mp-svg-plus-circled-grey mp-Icon mp-Icon--xl"></div>
</div>
</div>
<input type="hidden" name="images.urls" value="">
<input type="hidden" name="images.ids" value="">
<div id="html5_1dp0s4cfd1ro81fcdg1g1hi05p4_container" class="moxie-shim moxie-shim-html5" style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; overflow: hidden; z-index: 0;"><input id="html5_1dp0s4cfd1ro81fcdg1g1hi05p4" type="file" style="font-size: 999px; opacity: 0; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" multiple="" accept=".jpg,.jpeg,.png" tabindex="-1"></div></div><div class="uploader-container uploader-container--gray uploader-container--disabled"><div class="uploader-box"></div></div><div class="uploader-container uploader-container--gray uploader-container--disabled"><div class="uploader-box"></div></div><div class="uploader-container uploader-container--gray uploader-container--disabled"><div class="uploader-box"></div></div><div class="uploader-container uploader-container--gray uploader-container--disabled"><div class="uploader-box"></div></div></div>
最后一点:“ // div [@id] // input [@id]”似乎无效,并且新版本的Chromedriver可能比过去更加严格。删除或重写此部分,看看它是否有效。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句