GVKun编程网logo

如何使用Windows File Explorer和Selenium WebDriver选择许多文件(filebrowseraddbootoption怎么选)

22

最近很多小伙伴都在问如何使用WindowsFileExplorer和SeleniumWebDriver选择许多文件和filebrowseraddbootoption怎么选这两个问题,那么本篇文章就来给

最近很多小伙伴都在问如何使用Windows File Explorer和Selenium WebDriver选择许多文件filebrowseraddbootoption怎么选这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展Internet Explorer 11在通过IEDriverServer和Selenium执行测试时被随机卡住、org.openqa.selenium.WebDriver.Window的实例源码、Selenium WebDriver和浏览器选择文件对话框、Selenium Webdriver选择新窗口C#等相关知识,下面开始了哦!

本文目录一览:

如何使用Windows File Explorer和Selenium WebDriver选择许多文件(filebrowseraddbootoption怎么选)

如何使用Windows File Explorer和Selenium WebDriver选择许多文件(filebrowseraddbootoption怎么选)

我正在自动化一个UI测试,其中涉及选择要上传的文件,我能够使用此解决方案自动化文件选择。

WebElement filepath=driver.findElement(By.id("fileUploadId"));filepath.sendKeys("C:\\TextFile.txt");

我的问题是我需要选择许多要上传的文件,在发送的路径中应该遵循一种特殊的格式吗?因为我尝试了用空格分隔的路径,但没有用。

答案1

小编典典

上传多个文件, 您可以构造 字符串, 并添加文件的所有 绝对路径 ,并用分隔,\n如下所示:

WebElement filepath = driver.findElement(By.id("fileUploadId"));filepath.sendKeys("C:/TextFile1.txt \n C:/TextFile2.txt \n C:/TextFile3.txt");

Internet Explorer 11在通过IEDriverServer和Selenium执行测试时被随机卡住

Internet Explorer 11在通过IEDriverServer和Selenium执行测试时被随机卡住

我遇到了IE版本11随机卡在某些页面上的问题。该代码工作正常,因为每当我重新启动该程序时,有时它就可以工作,但最烦人的将是在单击并加载页面后随机卡住。在IE上正常吗?使用Chrome时,我从未遇到过此类问题。但是此网站仅适用于IE。我能知道这个问题的原因是驱动程序吗?网站本身吗?还是网络安全?

org.openqa.selenium.WebDriver.Window的实例源码

org.openqa.selenium.WebDriver.Window的实例源码

项目:marathonv5    文件:JavaDriverTest.java   
public void windowSetSize() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeto(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    Dimension actual = window.getSize();
    AssertJUnit.assertNotNull(actual);
    java.awt.Dimension expected = EventQueueWait.call(frame,"getSize");
    AssertJUnit.assertEquals(expected.width,actual.width);
    AssertJUnit.assertEquals(expected.height,actual.height);
    window.setSize(new Dimension(expected.width * 2,expected.height * 2));
    actual = window.getSize();
    AssertJUnit.assertEquals(expected.width * 2,actual.width);
    AssertJUnit.assertEquals(expected.height * 2,actual.height);
}
项目:marathonv5    文件:JavaDriverTest.java   
public void windowSetPosition() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeto(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    Point actual = window.getPosition();
    AssertJUnit.assertNotNull(actual);
    java.awt.Point expected = EventQueueWait.call(frame,"getLocation");
    AssertJUnit.assertEquals(expected.x,actual.x);
    AssertJUnit.assertEquals(expected.y,actual.y);
    window.setPosition(new Point(expected.x + 10,expected.y + 10));
    actual = window.getPosition();
    AssertJUnit.assertEquals(expected.x + 10,actual.x);
    AssertJUnit.assertEquals(expected.y + 10,actual.y);
}
项目:marathonv5    文件:JavaDriverTest.java   
public void nonFrameDialogWindowUsesNameIfExistsAsTitle() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setVisible(true);
            window = new java.awt.Window(frame);
            window.setName("awt-window");
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(new JTextField(80));
            window.setLayout(new BorderLayout());
            window.add(panel,BorderLayout.CENTER);
            window.setSize(640,480);
            window.setLocationRelativeto(frame);
            window.requestFocus();
            window.setVisible(true);
        }
    });
    try {
        Thread.sleep(200);
        AssertJUnit.assertEquals("awt-window",driver.getTitle());
    } finally {
        window.dispose();
    }
}
项目:marathonv5    文件:JavaDriverTest.java   
public void nonFrameDialogWindowUsesClassNameAsTitleOnLastResort() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setVisible(true);
            window = new java.awt.Window(frame);
            window.setName(null);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(new JTextField(80));
            window.setLayout(new BorderLayout());
            window.add(panel,480);
            window.setLocationRelativeto(frame);
            window.requestFocus();
            window.setVisible(true);
        }
    });
    try {
        Thread.sleep(200);
        AssertJUnit.assertEquals("java.awt.Window",driver.getTitle());
    } finally {
        window.dispose();
    }
}
项目:bootstrap    文件:TAbstractSeleniumTest.java   
@SuppressWarnings("unchecked")
@Override
protected void prepareDriver() throws Exception {
    System.clearProperty("test.selenium.remote");
    localDriverClass = WebDriverMock.class.getName();
    remoteDriverClass = WebDriverMock.class.getName();
    scenario = "sc";
    super.prepareDriver();
    mockDriver = Mockito.mock(WebDriverMock.class);
    Mockito.when(mockDriver.getScreenshotAs(ArgumentMatchers.any(OutputType.class)))
            .thenReturn(new File(Thread.currentThread().getContextClassLoader().getResource("log4j2.json").toURI()));
    final Options options = Mockito.mock(Options.class);
    Mockito.when(options.window()).thenReturn(Mockito.mock(Window.class));
    Mockito.when(mockDriver.manage()).thenReturn(options);
    final WebElement webElement = Mockito.mock(WebElement.class);
    Mockito.when(mockDriver.findElement(ArgumentMatchers.any(By.class))).thenReturn(webElement);
    Mockito.when(webElement.isdisplayed()).thenReturn(true);
    this.driver = mockDriver;
}
项目:bootstrap    文件:TAbstractParallelSeleniumTest.java   
@SuppressWarnings("unchecked")
@Override
protected void prepareDriver() throws Exception {
    testName = Mockito.mock(TestName.class);
    Mockito.when(testName.getmethodName()).thenReturn("mockTest");
    System.clearProperty("test.selenium.remote");
    localDriverClass = WebDriverMock.class.getName();
    remoteDriverClass = WebDriverMock.class.getName();
    scenario = "sc";
    super.prepareDriver();
    mockDriver = Mockito.mock(WebDriverMock.class);
    Mockito.when(((WebDriverMock) mockDriver).getScreenshotAs(ArgumentMatchers.any(OutputType.class))).thenReturn(
            new File(Thread.currentThread().getContextClassLoader().getResource("log4j2.json").toURI()));
    final Options options = Mockito.mock(Options.class);
    Mockito.when(options.window()).thenReturn(Mockito.mock(Window.class));
    Mockito.when(mockDriver.manage()).thenReturn(options);
    final WebElement webElement = Mockito.mock(WebElement.class);
    Mockito.when(mockDriver.findElement(ArgumentMatchers.any(By.class))).thenReturn(webElement);
    Mockito.when(webElement.isdisplayed()).thenReturn(true);
    this.driver = mockDriver;
}
项目:bootstrap    文件:TAbstractSequentialSeleniumTest.java   
@SuppressWarnings("unchecked")
@Override
protected void prepareDriver() throws Exception {
    testName = Mockito.mock(TestName.class);
    Mockito.when(testName.getmethodName()).thenReturn("mockTest");
    System.clearProperty("test.selenium.remote");
    localDriverClass = WebDriverMock.class.getName();
    remoteDriverClass = WebDriverMock.class.getName();
    scenario = "sc";
    super.prepareDriver();
    mockDriver = Mockito.mock(WebDriverMock.class);
    Mockito.when(((WebDriverMock) mockDriver).getScreenshotAs(ArgumentMatchers.any(OutputType.class))).thenReturn(
            new File(Thread.currentThread().getContextClassLoader().getResource("log4j2.json").toURI()));
    final Options options = Mockito.mock(Options.class);
    Mockito.when(options.window()).thenReturn(Mockito.mock(Window.class));
    Mockito.when(mockDriver.manage()).thenReturn(options);
    final WebElement webElement = Mockito.mock(WebElement.class);
    Mockito.when(mockDriver.findElement(ArgumentMatchers.any(By.class))).thenReturn(webElement);
    Mockito.when(webElement.isdisplayed()).thenReturn(true);
    this.driver = mockDriver;
}
项目:bootstrap    文件:TAbstractRepeatableSeleniumTest.java   
@SuppressWarnings("unchecked")
@Override
protected void prepareDriver() throws Exception {
    System.clearProperty("test.selenium.remote");
    localDriverClass = WebDriverMock.class.getName();
    remoteDriverClass = WebDriverMock.class.getName();
    scenario = "sc";
    super.prepareDriver();
    mockDriver = Mockito.mock(WebDriverMock.class);
    Mockito.when(mockDriver.getScreenshotAs(ArgumentMatchers.any(OutputType.class))).thenReturn(
            new File(Thread.currentThread().getContextClassLoader().getResource("log4j2.json").toURI()));
    final Options options = Mockito.mock(Options.class);
    Mockito.when(options.window()).thenReturn(Mockito.mock(Window.class));
    Mockito.when(mockDriver.manage()).thenReturn(options);
    final WebElement webElement = Mockito.mock(WebElement.class);
    Mockito.when(mockDriver.findElement(ArgumentMatchers.any(By.class))).thenReturn(webElement);
    Mockito.when(webElement.isdisplayed()).thenReturn(true);
    this.driver = mockDriver;
}
项目:marathonv5    文件:JavaDriverTest.java   
public void windowSize() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeto(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    Dimension actual = window.getSize();
    AssertJUnit.assertNotNull(actual);
    java.awt.Dimension expected = EventQueueWait.call(frame,actual.height);
}
项目:marathonv5    文件:JavaDriverTest.java   
public void windowPosition() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeto(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    Point actual = window.getPosition();
    AssertJUnit.assertNotNull(actual);
    java.awt.Point expected = EventQueueWait.call(frame,actual.y);
}
项目:marathonv5    文件:JavaDriverTest.java   
public void windowMaximize() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeto(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    window.maximize();
}
项目:willtest    文件:DefaultFirefoxConfigurationParticipant.java   
/**
 * Moves window to the first display,and maximizes there.
 * This is practical in case of local testing.
 *
 * @see WebDriverConfigurationParticipant#postconstruct(WebDriver)
 */
@Override
public void postconstruct(D webDriver) {
    Window window = webDriver.manage().window();
    Dimension dimension = new Dimension(1920,1080);
    Point thisPointIsAlwaysOnFirstdisplay = new Point(0,0);
    window.setPosition(thisPointIsAlwaysOnFirstdisplay);
    window.setSize(dimension);
    window.maximize();
}
项目:aet    文件:ResolutionModifier.java   
private void setResolution(WebDriver webDriver) {
  Window window = webDriver.manage().window();
  if (maximize) {
    window.maximize();
    LOG.error("Trying to maximise window to  {}x{}!",window.getSize().getWidth(),window.getSize().getHeight());
  } else {
    LOG.info("Setting resolution to  {}x{}  ",width,height);
    window.setSize(new Dimension(width,height));
  }
}
项目:webtester-core    文件:WebDriverbrowserTest.java   
private Window mockWindow() {
    Options options = mock(Options.class);
    doReturn(options).when(webDriver).manage();
    Window window = mock(Window.class);
    doReturn(window).when(options).window();
    return window;
}
项目:qir    文件:AbstractWebITCase.java   
@Before
public void initData() {
    dataInitService.clear();
    dataInitService.init();
    webDriver = new PhantomJSDriver();
    final Options options = webDriver.manage();
    final Window window = options.window();
    window.setSize(new Dimension(1280,800));
}
项目:webtester-core    文件:WebDriverbrowserTest.java   
@Test
public void testThatMaximizingTheCurrentwindowInvokesCorrectWebDriverMethods() {
    Window window = mockWindow();
    cut.maximizeCurrentwindow();
    verify(window).maximize();
}
项目:fitnesse-selenium-slim    文件:SeleniumFixture.java   
/**
 * <p>
 * <code>
 * | window maximize |
 * </code>
 * </p>
 * Resize currently selected window to take up the entire screen
 *
 * @return the window size after maximizing
 */
public String windowMaximize() {
    return SeleniumFixture.WEB_DRIVER.getWhenAvailable(StringUtils.EMPTY,(driver,parsedLocator) -> {
        Window window = driver.manage().window();
        window.maximize();
        return this.fitnesseMarkup.formatWidthAndHeight(window.getSize().getWidth(),window.getSize().getHeight());
    });
}

Selenium WebDriver和浏览器选择文件对话框

Selenium WebDriver和浏览器选择文件对话框

如何解决Selenium WebDriver和浏览器选择文件对话框?

如果您尝试选择要上传的文件,则Selenium 2支持HTML文件输入。例如:

<input type="file" id="uploadhere" />

IWebElement element = driver.FindElement(By.Id("uploadhere"));
element.SendKeys("C:\\Some_Folder\\MyFile.txt");

基本上,您“输入”(带有SendKeys)文件输入元素的完整文件路径。Selenium为您处理文件选择对话框。

但是,如果您想操纵任意文件选择对话框,那么就像Anders所说的那样,您必须走出Selenium的门。

解决方法

我正在使用Selenium WebDriver,C#。

是否可以使用Firefox选择文件对话框来使网络驱动程序正常工作?还是我必须使用类似AutoIt的东西?

Selenium Webdriver选择新窗口C#

Selenium Webdriver选择新窗口C#

试图在C#中使用Selenium WebDriver编写一些测试用例,但有一个我不确定如何解决的方案

用户场景是在表中搜索患者,选择患者,然后打开一个新窗口,然后在该窗口上声明各种项目

我的问题是我无法选择新窗口来声明任何内容,它不是弹出窗口,这是一个全新的浏览器窗口,但是没有窗口标题/名称来标识它,我将如何将驱动程序焦点切换到此窗口?

提前致谢

答案1

小编典典

在Selenium WebDriver中,这真的很容易。通过使用SwitchTo方法

driver.SwitchTo().Window(driver.WindowHandles.Last());

也请参阅此博客文章

http://binaryclips.com/2015/03/13/selenium-webdriver-in-c-switch-to-new-
window/

关于如何使用Windows File Explorer和Selenium WebDriver选择许多文件filebrowseraddbootoption怎么选的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于Internet Explorer 11在通过IEDriverServer和Selenium执行测试时被随机卡住、org.openqa.selenium.WebDriver.Window的实例源码、Selenium WebDriver和浏览器选择文件对话框、Selenium Webdriver选择新窗口C#的相关知识,请在本站寻找。

本文标签: