Issue
This Content is from Stack Overflow. Question asked by jyra
so I want to do an automated testing on an iframe (input image). Here is what I have done so far:
WebDriverWait(driver, 1000).until(EC.frame_to_be_available_and_switch_to_it(driver.find_element("xpath","//div[@id='el_banner_url_upload']//iframe")))
upload_image = driver.find_element("xpath", "//input[@name='images']")
upload_image.send_keys(str(d_image))
driver.switch_to.default_content()
For the flow:
- I click on a button inside the iframe
- It opens my windows folder, then I select a picture I want to upload
- The image uploaded and it gives a preview + a link to the image that is generated automatically by the website is shown on the field below the displayed image
Here is the link to the screenshot of what I’m talking about:
I got 2 problems right now,
- After running the script, it works well (didn’t give any error on the command). The “upload” button is gone now. But, the image is not shown on the display and there are no link generated. As shown in this screenshot. Tried inspect it, and found this error on the console:
Uncaught TypeError: Cannot read properties of undefined (reading 'showQuality')
at HTMLFormElement.add (pic-embed.js:173:35)
at $.<computed>.<computed>._trigger (jquery.ui.widget.js:489:13)
at File.<anonymous> (jquery.fileupload.js:846:31)
at Function.each (jquery.js:4:5347)
at $.<computed>.<computed>._onAdd (jquery.fileupload.js:840:15)
at $.<computed>.<computed>._onAdd (jquery.ui.widget.js:105:25)
at Object.<anonymous> (jquery.fileupload.js:1016:26)
at c (jquery.js:4:26036)
at Object.add [as done] (jquery.js:4:26346)
at Object.always (jquery.js:4:27212)
- The iframe would randomly not refreshed correctly, this too I couldn’t figure out how. If this happens, the script couldn’t run. Here is the screenshot of when the iframe didn’t refresh correctly
Are there any solution to this?
Solution
You should use Selenium expected conditions. Don’t just find elements and click them, wait for them to be enabled or clickable:
driver.wait.until(ExpectedCondition.element_to_be_clickable((By.XPATH, "myXpath"))).click()
driver.wait.until(ExpectedCondition.element_to_be_clickable((By.CSS, "myCSS"))).click()
When you try to click on an element before it is actually clickable – you are going to get errors.
This Question was asked in StackOverflow by jyra and Answered by Tal Angel It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.