Python Selenium 调用隐藏文件输入
Python Selenium Calling Hidden File Input
我正在使用 selenium-python 和 chromedriver。
在 https://web.whatsapp.com/ 的网页中,我试图将带有 send_keys() 的文件发送到文件类型输入。
但问题是,当您将文件拖放到 webpage.If 上时,输入元素仅在检查器中可见,您关闭该菜单(我不是说本机菜单)元素从检查器中消失。
如果元素没有显示,如何调用该元素?
元素看起来是这样的:
xpath='//*[@id="app"]/div/div[3]/div[1]/span[2]/span/div/div[2]/input'
<input type="file" accept="image/*,video/*" multiple="" style="display: none;">
我试过了
driver.execute_script("document.getElementById('parent_id').style.display='block';")
driver.execute_script("document.getElementByXpath('Xpath').sendKeys('file');")
但其中 none 有效。
如果您想使用文件输入元素,请尝试使其可见,而不是如下所示的父元素:
xpath = '//*[@id="app"]/div/div[3]/div[1]/span[2]/span/div/div[2]/input'
file = driver.find_element_by_xpath(xpath)
file = driver.execute_script("arguments[0].style.display='block'; return arguments[0];", file)
file.seng_keys("file")
我正在使用 selenium-python 和 chromedriver。
在 https://web.whatsapp.com/ 的网页中,我试图将带有 send_keys() 的文件发送到文件类型输入。
但问题是,当您将文件拖放到 webpage.If 上时,输入元素仅在检查器中可见,您关闭该菜单(我不是说本机菜单)元素从检查器中消失。
如果元素没有显示,如何调用该元素?
元素看起来是这样的:
xpath='//*[@id="app"]/div/div[3]/div[1]/span[2]/span/div/div[2]/input'
<input type="file" accept="image/*,video/*" multiple="" style="display: none;">
我试过了
driver.execute_script("document.getElementById('parent_id').style.display='block';")
driver.execute_script("document.getElementByXpath('Xpath').sendKeys('file');")
但其中 none 有效。
如果您想使用文件输入元素,请尝试使其可见,而不是如下所示的父元素:
xpath = '//*[@id="app"]/div/div[3]/div[1]/span[2]/span/div/div[2]/input'
file = driver.find_element_by_xpath(xpath)
file = driver.execute_script("arguments[0].style.display='block'; return arguments[0];", file)
file.seng_keys("file")