【问题标题】:Element Not Interactable even after moving to the element and explicitly waiting in Selenium Java即使在移动到元素并在 Selenium Java 中显式等待之后,元素也无法交互
【发布时间】:2019-07-29 21:18:18
【问题描述】:

当我点击供应商框时,它会弹出一个选项列表,您可以滚动到这些选项列表或键入您想要的内容并选择。该框具有明确的 id,并且在实际页面上绝对可以交互,但是当我运行测试时,它只是说元素不可交互。

我已经阅读了其他线程并尝试使用 Actions 移动到元素并显式等待,当我完成时,抛出了一个错误“等待元素的可见性”。 //尝试移动到元素

    Actions action = new Actions(driver);
    action.moveToElement(driver.findElement(By.id(TransactionUIConstants.VENDOR_SEARCH)));

    WebDriverWait wait = new WebDriverWait(driver, Page.TIMEOUT);
    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("vendor")))); 
    wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("vendor"))));
    //What I'm trying to click

    driver.findElement(By.id("vendor")).click();
    driver.findElement(By.id("vendor")).sendKeys("Amazon");
    driver.findElement(By.id("vendor")).sendKeys(Keys.ENTER);

这是检查选项卡中的描述:

input name="" id="vendor" type="text" autocomplete="nope" placeholder="Select option" tabindex="0" class="multiselect__input" style="width: 0px; position: absolute;内边距:0px;"

【问题讨论】:

  • 最后 3 行中的哪一行给出了关于不可交互的错误?还有哪个浏览器?我想我曾经通过将密钥发送到窗口或文档来解决此类问题。但是您是否需要发送密钥,或者如果您找到正确的文本并单击正确的选项同样好?
  • 因为假设第一次点击有效,你可以点击 xpath 找到的元素之后 //option[contains(text(), "Amazon")]
  • 这是第一行抛出错误,我试过只发送键而不点击,它也会抛出同样的错误。
  • 所以也许供应商真的是不可交互的,手动点击对它里面的东西做了一些事情。我想知道(尽管有些浏览器不喜欢你点击看不到的东西)javabeginnerstutorial.com/selenium/… 方法 1 第一个代码块的方法是否适合你。
  • 我得到了一些帮助,显然它是另一个库的一部分,所以我们最终不得不这样做:

标签: java selenium-webdriver selenium-chromedriver


【解决方案1】:

如果它有选择标签,你可以尝试使用选择类。我假设它可能是一个多选下拉列表

【讨论】:

  • 我也试过这个,但是当我运行它时,错误说,“元素应该是“选择”但是“输入”。
【解决方案2】:
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>javax.mail-api</artifactId>
        <version>1.5.5</version>
    </dependency>

    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>smtp</artifactId>
        <version>1.6.0</version>
    </dependency>

    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>javax.mail</artifactId>
        <version>1.6.0</version>
    </dependency>

【讨论】:

  • 1 2 3 4 5 6 mail.smtp.host=smtp.gmail.com mail.smtp.socketFactory.port=465 mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory 邮件.smtp.auth=true mail.smtp.port=465 mail.transport.protocol=smtp
  • 私人文件夹文件夹;公共枚举 EmailFolder { INBOX("INBOX"), SPAM("SPAM");私有字符串文本;私人电子邮件文件夹(字符串文本){ this.text = text; } public String getText() { 返回文本; } }
  • /** * 使用属性文件中的 email.username 和 email.password 属性。从电子邮件应用程序的收件箱文件夹中读取 * @throws MessagingException */ public EmailUtils() throws MessagingException { this(EmailFolder.INBOX); }
  • 您确定要回答这个问题吗?你的似乎是关于电子邮件,这是关于从列表中挑选一些东西。
【解决方案3】:
mail.smtp.host=smtp.gmail.com
mail.smtp.socketFactory.port=465
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
mail.smtp.auth=true
mail.smtp.port=465
mail.transport.protocol=smtp


resource folder-1

【讨论】:

    【解决方案4】:
    utility class- 2
    
     private Folder folder;
    
      public enum EmailFolder {
        INBOX("INBOX"),
        SPAM("SPAM");
    
        private String text;
    
        private EmailFolder(String text){
          this.text = text;
        }
    
        public String getText() {
          return text;
        }
      }
    

    【讨论】:

    • 您似乎对同一个问题发布了许多答案。您是要提供单独的答案,还是它们是一个大答案的一部分?
    【解决方案5】:
    /**
       * Uses email.username and email.password properties from the properties file. Reads from Inbox folder of the email application
       * @throws MessagingException
       */
      public EmailUtils() throws MessagingException {
        this(EmailFolder.INBOX);
      }
    
      /**
       * Uses username and password in properties file to read from a given folder of the email application
       * @param emailFolder Folder in email application to interact with
       * @throws MessagingException
       */
      public EmailUtils(EmailFolder emailFolder) throws MessagingException {
        this(getEmailUsernameFromProperties(),
            getEmailPasswordFromProperties(),
            getEmailServerFromProperties(),
            emailFolder);
      }
    
      /**
       * Connects to email server with credentials provided to read from a given folder of the email application
       * @param username Email username (e.g. janedoe@email.com)
       * @param password Email password
       * @param server Email server (e.g. smtp.email.com)
       * @param emailFolder Folder in email application to interact with
       */
      public EmailUtils(String username, String password, String server, EmailFolder emailFolder) throws MessagingException {
        Properties props = System.getProperties();
        try {
          props.load(new FileInputStream(new File("resources/email.properties")));
        } catch(Exception e) {
          e.printStackTrace();
          System.exit(-1);
        }
    
        Session session = Session.getInstance(props);
        Store store = session.getStore("imaps");
        store.connect(server, username, password);
    
    
        folder = store.getFolder(emailFolder.getText());
        folder.open(Folder.READ_WRITE);
      }
    

    【讨论】:

      猜你喜欢
      • 2020-12-03
      • 1970-01-01
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-05
      • 1970-01-01
      相关资源
      最近更新 更多