以下是HTML页面:
<li data-picture-status="off">
<p class="picture-uploader-add">Adicionar</p>
<div class="picture-uploader-controls">
<a role="button" class="ch-close ch-hide" href="#"><span class="ch-hide">Excluir</span></a>
</div>
<p class="picture-uploader-principal">Foto principal</p>
</li>
<div class="picture-uploader-controls">
<a role="button" class="ch-close ch-hide" href="#"><span class="ch-hide">Excluir</span></a>
</div>
这是我的python代码:
driver = webdriver.Chrome()
driver.maximize_window()
time.sleep(10)
driver.find_element_by_xpath('//p[@class="picture-uploader add"]').send_keys('C:/image.jpg')
这是错误:
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element
答案 0 :(得分:1)
您似乎正在尝试处理错误的元素...请尝试处理<input type="file">
:
driver.find_element_by_xpath('//input[@type="file"]').send_keys('C:/image.jpg')