Селен веб-драйвер говорит, что элемент не взаимодействует - PullRequest
0 голосов
/ 10 февраля 2020

цель : я хочу автоматизировать загрузку вложения в Интернет онлайн с помощью веб-драйвера Selenium с объектной моделью страницы и фабрикой страниц.

ожидаемый результат : просто текстовый файл должен быть прикреплен или загружен в SharePoint.

фактический результат : ниже приводится трассировка стека, которую я получаю.

org.openqa.selenium.ElementNotInteractableException: element not interactable
  (Session info: chrome=79.0.3945.88)
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'localhost.localdomain', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1062.9.1.el7.x86_64', java.version: '1.8.0_221'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.88, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389..., userDataDir: /tmp/.com.google.Chrome.EBImpo}, goog:chromeOptions: {debuggerAddress: localhost:38140}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 91482c621b92cb13e5522cac8b60cb3e
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:276)
    at org.openqa.selenium.remote.RemoteWebElement.clear(RemoteWebElement.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:51)
    at com.sun.proxy.$Proxy40.clear(Unknown Source)
    at com.persistent.connectors.testsuite.client.datasourceservice.sharepoint.webpages.AnnouncementAttachPage.setAttachment_field(AnnouncementAttachPage.java:78)
    at com.persistent.connectors.testsuite.sharepointonline.api.LoginTest.login(LoginTest.java:136)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

I ' Я использую SharePoint онлайн, чтобы загрузить файл (прикрепить) пользовательское приложение, которое я создал. Это имя announcecment01

Ниже приведены шаги с примерами кода.

  1. Изначально я получил все необходимые веб-элементы для класса.

    AnnouncementAttachPage. java

ниже ошибок кода, указывающих мне, когда я пытаюсь получить доступ к setAttachment_field (String path) метод.

package com.persistent.connectors.testsuite.client.datasourceservice.sharepoint.webpages;

import org.apache.log4j.Logger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.concurrent.TimeUnit;

public class AnnouncementAttachPage {

    final Logger logger = Logger.getLogger(AnnouncementAttachPage.class);

    private WebDriver driver;

    // page url
    private static final String PAGE_URL = "https://***.sharepoint.com/sites/***/Lists/announcment01/AllItems.aspx";

    // constructor
    public AnnouncementAttachPage(WebDriver driver) {
        this.driver = driver;
        driver.get(PAGE_URL);
        // initialize elements
        PageFactory.initElements(driver, this);
    }

    // get the new button
    @FindBy(xpath = "//*[@id=\"appRoot\"]/div[1]/div[3]/div/div[2]/div[1]/div/div[3]/div/div/div/div/div/div/div/div[1]/div[1]/button")
    private WebElement new_button;

    // get the title element
    @FindBy(xpath = "/html/body/div[1]/div/div/div[5]/div/div/div/div/div[2]/div/div/div[3]/div/div[2]/div[1]/span/div[1]/div/div/input")
    private WebElement title_field;

    // get the expire date
    @FindBy(xpath = "/html/body/div[1]/div/div/div[5]/div/div/div/div/div[2]/div/div/div[3]/div/div[2]/div[3]/span/div[1]/div/div/div/div/input")
    private WebElement expire_date;

    // get the attachment input field
    @FindBy(xpath = "//*[@id=\"appRoot\"]/div[5]/div/div/div/div/div[2]/div/div/div[3]/div/div[2]/div[4]/span/div[1]/div/div/input")
    private WebElement attachment_field;

    // get the attachment button
    @FindBy(xpath = "//*[@id=\"appRoot\"]/div[5]/div/div/div/div/div[2]/div/div/div[3]/div/div[2]/div[4]/span/div[1]/div/div/button")
    private WebElement attachment_button;

    // get the save button
    @FindBy(xpath = "//*[@id=\"appRoot\"]/div[5]/div/div/div/div/div[2]/div/div/div[3]/div/div[3]/button[1]")
    private WebElement save_button;

    public void clickOnNewButton() {
        this.new_button.click();
        logger.info("new button is clicked of announcement tab...");
    }

    public void setTitle_field(String title) {
        this.title_field.clear();
        this.title_field.sendKeys(title);
        logger.info("title field is set...");
    }

    public void setExpire_date(String date) {
        this.expire_date.clear();
        this.expire_date.sendKeys(date);
        logger.info("expire date is set...");
    }

    public void setAttachment_field(String path) {
        this.attachment_field.clear();

        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.elementToBeClickable(attachment_field));

        this.attachment_field.sendKeys(path);
        logger.info("file path is set to upload");
    }

    public void clickOnAddAttachmentButton() {
        this.attachment_button.click();
    }

    public void clickOnSaveButton() {
        this.save_button.click();
        logger.info("save button clicked...");
    }


}

Ниже приведен класс теста, в котором я запускаю тест.

LoginTest. java

package com.persistent.connectors.testsuite.sharepointonline.api;

import com.persistent.connectors.testsuite.client.datasourceservice.sharepoint.webpages.*;
import net.thucydides.core.annotations.WithTag;
import net.thucydides.core.annotations.WithTags;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

@WithTags(
        {
                @WithTag("web ui tests"),
                @WithTag(type = "suite", name = "api"),
                @WithTag(type = "package", name = ""),
                @WithTag(type = "class", name = "LoginTest")
        }
)

public class LoginTest {

    final Logger logger = Logger.getLogger(LoginTest.class);

    private WebDriver driver;

    @Before
    public void setup() throws InterruptedException {
        // use chrome driver
        System.setProperty("webdriver.chrome.driver", "/data/code/2019/aws-connector-functional-testsuite/lib/chromedriver");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--start-maximized");

        // chrome
        driver = new ChromeDriver(options);

        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    }

    @Test
    @WithTag("SWD-001")
    public void login() throws InterruptedException {

       // there are some code lines here. I didn't include it. because I've tested out those and 
       // worked fine as expected.

        AnnouncementAttachPage announcementAttachPage = new AnnouncementAttachPage(driver);
        logger.info("Announcement Attach Page object is created...");
        announcementAttachPage.clickOnNewButton();
        announcementAttachPage.setTitle_field("sample");
        announcementAttachPage.setExpire_date("2/27/2020");

        // after this line I got the error

        //announcementAttachPage.clickOnAddAttachmentButton();
        announcementAttachPage.setAttachment_field("/home/centos/sample.txt");

        announcementAttachPage.clickOnSaveButton();
    }


    @After
    public void close() {
        //driver.close();
        //logger.info("driver object is closed...");
    }

}

Ниже приведен пользовательский интерфейс, который я пытаюсь автоматизировать.

enter image description here

  • Чтобы загрузить файл, нажмите кнопку «Добавить вложение», затем выберите файл в проводнике и нажмите кнопку «Сохранить».
  • , поскольку я автоматизирую эту задачу, мне не следует открывать проводник, когда я указываю путь к расположению файла, это должно быть видно здесь.

, так что эту часть я не мог сделать до сих пор. это означает, что при указании пути к файлу он не отображается в пользовательском интерфейсе.

Как мне решить эту проблему? Любая помощь будет высоко ценится.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...