【问题标题】:Unable to input email id to the field (Using python 3.10 and selenium 4.4.3)无法在字段中输入电子邮件 ID(使用 python 3.10 和 selenium 4.4.3)
【发布时间】:2022-09-30 19:51:15
【问题描述】:

无法在该字段中输入电子邮件 ID 可以帮助我解决这些错误。[代码错误2

serviceC = Service(r\"C:\\chromedriver_win32\\chromedriver.exe\")
driver = webdriver.Chrome(service=serviceC)

# My gmail credentials
my_username = \"my_mail_id@fake.com\"
my_password = \"mypassword\"

# open Wev.flock.com login
driver.get(\"http://web.flock.com\")

print(\"Website link\")
driver.implicitly_wait(10)

# Get started With Flock
Enter_email_id = driver.find_element(By.XPATH, \'//*[@id=\"widgets_InputBox_0\"]/input\')
# XPATH = \'//*[@id=\"widgets_InputBox_0\"]/input\'
# Full XPATH = \'/html/body/div[3]/div/div[1]/div/div/div[3]/div[3]/input\'
Enter_email_id.send_keys(my_username)


# automatically close the driver after 30 seconds
time.sleep(30)
driver.close()

下面我通过终端附加输出 主要问题是我无法找到输入字段的正确地址selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:{\"method\":\"xpath\",\"selector\":\"//*[@id=\"widgets_InputBox_0 \“]/输入\”}

任何帮助,将不胜感激

    DevTools listening on ws://127.0.0.1:55084/devtools/browser/fa303344-68e7-4306-a7fd-511ef7d18a15
Website link
[1676:6032:0925/155230.539:ERROR:device_event_log_impl.cc(214)] [15:52:30.540] USB: usb_service_win.cc:415 Could not read device interface GUIDs: The system cannot find the file specified. (0x2)
[1676:6032:0925/155230.540:ERROR:device_event_log_impl.cc(214)] [15:52:30.540] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[1676:6032:0925/155230.541:ERROR:device_event_log_impl.cc(214)] [15:52:30.542] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
Traceback (most recent call last):
  File \"d:\\Projects\\FlockAutomation.py\", line 22, in <module>
    Enter_email_id = driver.find_element(By.XPATH, \'//*[@id=\"widgets_InputBox_0\"]/input\')
  File \"C:\\Users\\itadmin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py\", line 855, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File \"C:\\Users\\itadmin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py\", line 428, in execute
    self.error_handler.check_response(response)
  File \"C:\\Users\\itadmin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\selenium\\webdriver\\remote\\errorhandler.py\", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
**selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//*[@id=\"widgets_InputBox_0\"]/input\"}**
  (Session info: chrome=105.0.5195.127)
Stacktrace:
Backtrace:
        Ordinal0 [0x007BDF13+2219795]
        Ordinal0 [0x00752841+1779777]
        Ordinal0 [0x0066423D+803389]
        Ordinal0 [0x00693025+995365]
        Ordinal0 [0x006931EB+995819]
        Ordinal0 [0x006C0F52+1183570]
        Ordinal0 [0x006AE844+1108036]
        Ordinal0 [0x006BF192+1175954]
        Ordinal0 [0x006AE616+1107478]
        Ordinal0 [0x00687F89+950153]
        Ordinal0 [0x00688F56+954198]
        GetHandleVerifier [0x00AB2CB2+3040210]
        GetHandleVerifier [0x00AA2BB4+2974420]
        GetHandleVerifier [0x00856A0A+565546]
        GetHandleVerifier [0x00855680+560544]
        Ordinal0 [0x00759A5C+1808988]
        Ordinal0 [0x0075E3A8+1827752]
        Ordinal0 [0x0075E495+1827989]
        Ordinal0 [0x007680A4+1867940]
        BaseThreadInitThunk [0x75B46739+25]
        RtlGetFullPathName_UEx [0x76FD8FD2+1218]
        RtlGetFullPathName_UEx [0x76FD8F9D+1165]

    标签: python selenium selenium-webdriver


    【解决方案1】:

    元素在iframe里面,你可以先定位iframe, 我使用另一个 python 库,只需要 3 行代码就可以实现这种自动化。 它使用浏览器扩展程序,您需要先通过代码cc.chrome.extension.install_or_update() 安装扩展程序

    从 clicknium 导入 clicknium 作为 cc、定位器、ui

    tab = cc.chrome.open('https://web.flock.com/')
    iframe = tab.find_element_by_xpath('//[@id="dijit__WidgetsInTemplateMixin_0"]/iframe') iframe.find_element_by_xpath('//[@id="widgets_InputBox_0"]/input').set_text("test")

    【讨论】:

    • 无法将元素记录为尝试使用定位器捕获元素它会通过打开新选项卡引发错误(新选项卡上的错误为 404。) Cilcknium 已更新(v0.1.9)
    【解决方案2】:

    我确实得到了答案,它很简单,只需指向 iframe,然后指向要输入或单击的元素。

    iframe = driver.find_element( By.XPATH, '//*[@id="dijit__WidgetsInTemplateMixin_0"]/iframe' ) driver.switch_to.frame(iframe)

    开始使用羊群

    Enter_email_id = driver.find_element(By.XPATH, '//*[@id="widgets_InputBox_0"]/input') driver.implicitly_wait(5) Enter_email_id.send_keys(my_username)

    Login_or_create_btn = driver.find_element( By.XPATH, '//*[@id="uniqName_15_0"]/div[3]/button' )

    Login_or_create_btn.click()

    sign_in_with_google=driver.find_element(By.XPATH,'//*[@id="uniqName_17_0"]/div[2]/button') sign_in_with_google.click()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-09
      • 2012-04-05
      • 1970-01-01
      • 2014-05-22
      • 2020-04-25
      相关资源
      最近更新 更多