我使用以下代码上传多个图像:
import selenium
import time
import selenium.common.exceptions
import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.action_chains import ActionChains
#provie file path for Chromedriver
chromedriver = "C:/Users/chromedriver_win32/chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.get("https://url.com")
#log in to the website
driver.find_element_by_id('ctrlLogin_UserName').send_keys("xyz.com")
driver.find_element_by_id('ctrlLogin_Password').send_keys("abc@01")
driver.find_element_by_id('ctrlLogin_LoginButton').click()
#give some time for all objects to load
time.sleep(5)
driver.maximize_window()
#click open Reports tab
driver.find_element_by_xpath('full XPath').click()
#navigate to New Reports
driver.switch_to.frame("hostFrame")
driver.find_element_by_xpath('full XPath').click()
#give some time for all Reports to load
time.sleep(5)
driver.switch_to.default_content()
#Open Report folder
time.sleep(5)
driver.switch_to.frame("hostFrame")
driver.find_element_by_xpath('full XPath').click()
time.sleep(5)
driver.execute_script("window.scrollTo(0, 600);")
driver.find_element_by_xpath('full XPath').click()
time.sleep(2)
driver.find_element_by_xpath('full XPath').click()
uploader = driver.find_element_by_xpath('full XPath')
uploader.send_keys("C:/Users/blabla.jpg")
我收到一个错误:引发exception_class(消息、屏幕、堆栈(selenium.com.mon.exceptions.ElementNotInteractiableException:消息:元素不可交互(会话信息:chrome=87.0.4280.88(
我试着添加等待,但也没用。有人能分享一些想法吗?
无法与元素交互,因为它不可见,或者另一个元素正在上面显示。仔细检查它是否处于可以与它交互且可见的状态,以及是否有正确的定位器。尝试更改
uploader.send_keys("C:\Users\blabla.jpg")
和:
scro=driver.find_element_by_xpath('full XPath')
scro.location_once_scrolled_into_view
scro.click()