即使移到元素并在Selenium Java中显式等待,元素也无法交互

时间:2019-07-29 21:18:18

标签: java selenium-webdriver selenium-chromedriver

当我单击供应商框时,它会弹出并带有选项列表,您可以滚动至这些选项或键入所需的内容并进行选择。该框具有清晰的ID,并且在实际页面上肯定是可交互的,但是当我运行测试时,它只是说element是不可交互的。

我已经阅读了其他线程,并尝试使用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 =“选择选项” tabindex =“ 0” class =“ multiselect__input” style =“ width:0px; position:absolute;填充:0px;“

5 个答案:

答案 0 :(得分:0)

如果它具有select标记,则可以尝试使用select类。我假设这可能是一个多选下拉列表

答案 1 :(得分:0)

    <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>

答案 2 :(得分:0)

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

答案 3 :(得分:0)

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;
    }
  }

答案 4 :(得分:0)

/**
   * 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);
  }