0

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:

  1. I click on a button inside the iframe
  2. It opens my windows folder, then I select a picture I want to upload
  3. 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:

  1. Before uploading the image
  2. After uploading the image

I got 2 problems right now,

  1. 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)
  1. 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?

2
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Sep 19, 2022 at 4:54
  • Please read minimal reproducible example and tour then edit your post accordingly. Commented Sep 19, 2022 at 5:55

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer, is it different with using WebDriverWait(driver, 1000).until(EC.frame_to_be_available_and_switch_to_it(driver.find_element("xpath","//div[@id='el_banner_url_upload']//iframe"))) ?
@jyra You should try using the WebDriverWait also before you do sendKeys to the upload image element.
tried as you suggested but didn't work. Is there a way to automatically refresh the page and restart the script if Selenium is not able to locate the element? Because I'm suspecting that the iframe is not loaded perfectly so Unable to locate element: {"method":"xpath","selector":"//input[@name='images']"} error is always displayed even though after inspecting the page, the element is there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.