我正在尝试使用python和selenium在magento上自动执行产品上传,但是我在上传图像时遇到了问题。
我试图用 id="fileupload"
driver.find_element_by_id("fileupload").send_keys('C:\\Users\\PC\\Desktop\\Code\\magento-bot\\image1.png')
Run Code Online (Sandbox Code Playgroud)
这似乎可行,因为当我将鼠标指针放在上传区域时,文件名会显示出来,但是提交后没有图像。
我也尝试单击上传区域,然后通过执行以下操作选择要上传的文件:
uploadElement = driver.find_element_by_xpath('//html/body/div[2]/main/div[2]/div/div/div/div[2]/div[5]/div[2]/fieldset/div/div[2]/div[1]/div[1]/div[1]')
uploadElement.click()
driver.switch_to.active_element().send_keys(os.getcwd()+"\image1.png)
Run Code Online (Sandbox Code Playgroud)
但我最终遇到此错误'FirefoxWebElement' object is not callable
最后,我尝试像这样模拟拖放:
element = os.getcwd()+"\image1.png"
target = bot.find_element_by_id('fileupload')
ActionChains(bot).drag_and_drop(element, target).perform
Run Code Online (Sandbox Code Playgroud)
但我得到下面的错误
AttributeError("move_to requires a WebElement")
任何帮助将不胜感激。
当我尝试从我的 WordPress API 中提取图像 source_URL 时,出现TypeError: Undefined is not an object (evaluating 'subitem.media_details.sizes.medium.source_url') 。
https://i.stack.imgur.com/rhSZc.jpg
https://i.stack.imgur.com/T4PMO.jpg
上面附图中的错误消息指向以下代码行
{this.state.data && this.state.data.length > 0 && (
this.state.data.map(post => (
{post.featured_media > 0 && post._embedded['wp:featuredmedia'].filter(element => element.id == post.featured_media).map((subitem, index) => (
source={{ uri: subitem.media_details.sizes.medium.source_url }}
我已经查看了来自 WordPress API 的 JSON 数据,并且肯定有一个 URL。
class HomeScreen extends React.Component {
constructor(){
super();
this.state = {
data: null,
loaded: true,
error: null
}
}
baseURL = 'https://wordpress-URL';
getData = (ev)=>{
this.setState({loaded:false, error: null});
let url …
Run Code Online (Sandbox Code Playgroud)