Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iframe中找不到selenium Python中的元素_Python_Selenium Webdriver_Xpath_Css Selectors_Webdriverwait - Fatal编程技术网

在iframe中找不到selenium Python中的元素

在iframe中找不到selenium Python中的元素,python,selenium-webdriver,xpath,css-selectors,webdriverwait,Python,Selenium Webdriver,Xpath,Css Selectors,Webdriverwait,下面是我的HTML代码。我尝试过使用xpath,但仍然遇到一个异常,即无法在createaccount表单上找到元素。 由于所需元素位于中,因此要在元素上调用单击(),您必须: 将所需的帧的WebDriverWait设置为可用,并将其切换为可用() 将所需元素的WebDriverWait设置为可单击() 您可以使用以下任一选项: 使用CSS\u选择器: WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to

下面是我的HTML代码。我尝试过使用xpath,但仍然遇到一个异常,即无法在createaccount表单上找到元素。

由于所需元素位于
中,因此要在元素上调用
单击()
,您必须:

  • 将所需的
    帧的WebDriverWait设置为可用,并将其切换为可用()
  • 将所需
    元素的WebDriverWait设置为可单击()
  • 您可以使用以下任一选项:

    • 使用
      CSS\u选择器

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#accountFrame[src='/account/frame/login/create']")))
      WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[placeholder='Email'][data-test='create-account-email']"))).click()
      
    • 使用
      XPATH

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='accountFrame' and @src='/account/frame/login/create']")))
      WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Email' and @data-test='create-account-email']"))).click()
      
  • 注意:您必须添加以下导入:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

参考文献 您可以在以下内容中找到一些相关讨论:


您需要先切换到iframe,然后与元素交互。还请张贴您尝试过的内容,而不仅仅是图片。谢谢您的解决方案。它通过切换框架得到了修复。我在你的评论中看不到任何记号,因此我将其标记为有用的评论。