SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.18k stars 8.11k forks source link

[🐛 Bug]: Using Selenium Grid to run test cases on node machines, file uploads are not functioning. #13691

Closed zhao123haha closed 6 months ago

zhao123haha commented 6 months ago

What happened?

Using Selenium Grid to run test cases on node machines, file uploads are not functioning. I tried the following three methods but none of them were successful. But All three upload methods mentioned above can be successful on Selenium Hub. The file upload is not of the input type. How can it be operated to perform file uploads on the node machines?

How can we reproduce the issue?

def upload_file_other(self, locator, file_path, flag=False, is_sleep=True):
        """文件上传-非input类型"""
        self.driver._is_remote = False
        ele = self.find_element(locator)
        self.highLightElement(ele)
        if flag:
            webdriver.ActionChains(self.driver).move_to_element(ele).perform()
            self.driver.execute_script("arguments[0].click();", ele)
        else:
            webdriver.ActionChains(self.driver).move_to_element(ele).click(ele).perform()
        t.md_logger().info(f"点击元素:{locator}")
        file_path = util.file_path(file_path)
        common.upload_file(file_path)
        t.md_logger().info(f"选择本地文件:{file_path}")
        if is_sleep:
            time.sleep(1)

    def upload_file_gui(self, locator, file_path):
        self.driver._is_remote = False
        ele = self.find_element(locator)
        webdriver.ActionChains(self.driver).move_to_element(ele).click(ele).perform()
        time.sleep(2)
        file_path = util.file_path(file_path)
        pyautogui.write(file_path)
        time.sleep(2)
        pyautogui.press('enter')
        time.sleep(2)
        pyautogui.press('enter')

    def upload_file_autoit(self, locator, file_paths):
        ele = self.find_element(locator)
        webdriver.ActionChains(self.driver).move_to_element(ele).click(ele).perform()
        time.sleep(2)
        file_paths = util.file_path(file_paths)
        file_path = util.file_path_upload()
        try:
            if os.path.exists(file_path):
                os.system('%s %s' % (file_path, file_paths))
        except Exception as e:
            raise e

Relevant log output

Operating System

window10

Selenium version

python 3.8.2

What are the browser(s) and version(s) where you see this issue?

Chrome 104.0.5112.81

What are the browser driver(s) and version(s) where you see this issue?

104.0.5112

Are you using Selenium Grid?

v.3.5.3

github-actions[bot] commented 6 months ago

@zhao123haha, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

diemol commented 6 months ago

FIle uploads are meant to be used with the Hub or Standalone.

https://www.selenium.dev/documentation/webdriver/drivers/remote_webdriver/#uploads

zhao123haha commented 6 months ago

FIle uploads are meant to be used with the Hub or Standalone.

https://www.selenium.dev/documentation/webdriver/drivers/remote_webdriver/#uploads

driver.file_detector = LocalFileDetector() file_input = driver.find_element(By.CSS_SELECTOR, "input[type='file']") file_input.send_keys(upload_file) driver.find_element(By.ID, "file-submit").click()
This is a solution for file uploads using input types. How to solve the problem for file uploads that are not of input types?

zhao123haha commented 6 months ago

FIle uploads are meant to be used with the Hub or Standalone.

https://www.selenium.dev/documentation/webdriver/drivers/remote_webdriver/#uploads

image How to handle this type?

github-actions[bot] commented 6 months ago

💬 Please ask questions at:

diemol commented 6 months ago

That website has an input type for uploading files. Here is code that shows how to do it: https://elementalselenium.com/tips/1-upload-a-file

zhao123haha commented 6 months ago

That website has an input type for uploading files. Here is code that shows how to do it: https://elementalselenium.com/tips/1-upload-a-file

I already know the file upload method using < input > type, but I want to know about the file upload method using < div class="dz-success-mark dz-clickable" id="drag-drop-upload" >< /div >.Because my project doesn't use < input > for file uploads. image

github-actions[bot] commented 5 months ago

This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs.