2016-08-12 97 views
1

我使用的是與鍍鉻驅動程序的硒python。Python硒調用隱藏文件輸入

在網頁中,這是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');") 

但是沒有一次成功。

回答

0

如果您笏有文件輸入元件的作用,然後嘗試使其可見,而不是它的下面父元素:

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") 
+0

我NoSuchElementException.Selenium找不到的元素。 – kgb26

+0

只有在網頁上放置文件後才能看到元素。 – kgb26

+0

@。沙拉布謝謝,但它仍然無法找到元素。 – kgb26