小编Sha*_*dan的帖子

如何在使用chrome driver/firefox驱动程序时更改Webdriver中的文件下载位置

我试图通过在特定文件夹中使用另存为选项来保存图像.我找到了一种方法,通过另存为选项,我可以右键单击要保存的图像.但我遇到的问题是在获取os窗口后询问保存文件的位置我无法发送所需的位置,因为我不知道该怎么做.我经历了在这个论坛上提出的类似问题但到目前为止他们没有帮助.

代码是 -

对于Firefox-

public class practice {

 public void pic() throws AWTException{
     WebDriver driver;

     //Proxy Setting     
        FirefoxProfile profile = new FirefoxProfile();
        profile.setAssumeUntrustedCertificateIssuer(false);
        profile.setEnableNativeEvents(false);
        profile.setPreference("network.proxy.type", 1);
        profile.setPreference("network.proxy.http", "localHost");
        profile.setPreference("newtwork.proxy.http_port",3128);

        //Download setting
        profile.setPreference("browser.download.folderlist", 2);
        profile.setPreference("browser.helperapps.neverAsk.saveToDisk","jpeg");
        profile.setPreference("browser.download.dir", "C:\\Users\\Admin\\Desktop\\ScreenShot\\pic.jpeg");
        driver = new FirefoxDriver(profile);

        driver.navigate().to("http://stackoverflow.com/users/2675355/shantanu");
        driver.findElement(By.xpath("//*[@id='large-user-info']/div[1]/div[1]/a/div/img"));
        Actions action = new Actions(driver);
        action.moveToElement(driver.findElement(By.xpath("//*[@id='large-user-info']/div[1]/div[1]/a/div/img"))).perform();
        action.contextClick().perform();
        Robot robo = new Robot();
        robo.keyPress(KeyEvent.VK_V);
        robo.keyRelease(KeyEvent.VK_V);
    // Here I am getting the os window but don't know how to send the desired location
    }//method   
}//class
Run Code Online (Sandbox Code Playgroud)

对于铬 -

public class practice …
Run Code Online (Sandbox Code Playgroud)

java automated-tests file-upload download selenium-webdriver

19
推荐指数
3
解决办法
6万
查看次数

org.openqa.selenium.UnhandledAlertException:意外警报打开

我正在使用Chrome驱动程序并尝试测试网页.

通常它运行正常,但有一段时间我得到例外 -

 org.openqa.selenium.UnhandledAlertException: unexpected alert open
 (Session info: chrome=38.0.2125.111)
 (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 x86) (WARNING: The server did not  provide any stacktrace information)
 Command duration or timeout: 16 milliseconds: null
 Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:30'
 System info: host: 'Casper-PC', ip: '10.0.0.4', os.name: 'Windows 7', os.arch: 'x86', os.version:  '6.1', java.version: '1.8.0_25'
 Driver info: org.openqa.selenium.chrome.ChromeDriver
Run Code Online (Sandbox Code Playgroud)

然后我试着处理警报 -

  Alert alt = driver.switchTo().alert();
  alt.accept();
Run Code Online (Sandbox Code Playgroud)

但这次我复活了 - org.openqa.selenium.NoAlertPresentException

我附上警报的屏幕截图 - 第一次警报并使用esc或输入i获取第二个警报第二次警报

我现在无法弄明白该做什么.问题是我总是没有收到这个例外.当它发生时,测试失败.

javascript java selenium exception selenium-webdriver

17
推荐指数
2
解决办法
6万
查看次数

打印字符串比较结果时得到奇怪的输出

我正面临着这条线的问题(下面评论):

System.out.println("Using == ::"+s3==s4)
Run Code Online (Sandbox Code Playgroud)

哪个输出false.

但是,System.out.println(s3==s4)产出true.

现在,我无法理解为什么我得到这个结果:

public class string {
    public static void main(String[] args){
        String s3="Shantanu";
        String s4=s3;
        String s1=new String("java");
        String s2=new String("javaDeveloper");

        System.out.println("Using Equals Method::"+s1.equals(s2));
        System.out.println("Using Equals Method::"+s3.equals(s4));
        System.out.println("Using == ::"+s3==s4);//Problem is here in this line
        System.out.println(s1+"Directly printing the s2 value which is autocasted from superclass to string subclass ");
        System.out.println("Directly printing the s1 value which is autocasted from superclass to string subclass "+s2);
        System.out.println(s3);
    }
}
Run Code Online (Sandbox Code Playgroud)
Output-Using Equals Method::false …

java string

16
推荐指数
3
解决办法
757
查看次数

找不到记录器的附加程序(org.apache.http.client.protocol.RequestAddCookies)

我正在尝试在 Firefoxdriver 上运行 selenium webdriver 代码,但在运行时我遇到了异常——

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 15 milliseconds
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:30'
System info: host: 'Admin-PC', ip: '192.168.2.5', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_65'
Session ID: 826ebd51-0bc9-4900-b0ef-d68279bd19fe
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true,javascriptEnabled=true, acceptSslCerts=true, …
Run Code Online (Sandbox Code Playgroud)

java selenium log4j selenium-webdriver

5
推荐指数
1
解决办法
3万
查看次数

什么(com.microsoft.sqlserver.jdbc.SQLServerException:索引0超出范围)异常意味着什么

  import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.PrintWriter;
import java.sql.*;
import java.net.*;

public class connection {
    JTextField textfeild;
    JButton button;
    String text;
    Socket sock;
    PrintWriter writer;
    JButton button1;

    public static void main(String[] args) {
        connection user1 = new connection();
        user1.go();
    }//main method close

    public void go() {
        JFrame frame12 = new JFrame();
        JPanel centerpanel12 = new JPanel();
        centerpanel12.setLayout(new BoxLayout(centerpanel12, BoxLayout.Y_AXIS));
        textfeild = new JTextField(20);
        centerpanel12.add(textfeild);
        //textfeild.addActionListener(new textfeildlitner());
        frame12.add(centerpanel12);
        button = new JButton("Click Me");
        centerpanel12.add(button);
        button.addActionListener(new buttonlitner());
        button1 = new JButton("DataDisplay"); …
Run Code Online (Sandbox Code Playgroud)

java sql-server exception-handling sql-server-2005 jdbc

2
推荐指数
1
解决办法
4490
查看次数

字符串索引超出范围异常且for循环不起作用

我正在获得第一个for循环的正确输出:for(int i=0;i<=name.length();i++)但是不知道为什么我没有得到这个循环的任何输出:for(int i=name.length();i>=0;i--).执行时我收到错误,指出索引超出范围.

我在这里检查错误,但我不明白.

public class runner {
    public static void main(String[] args) {
        String name = "java";
        System.out.println(".length method()" + name.length());// executing
                                                                // .length()
                                                                // method
        System.out.println(".charAt method()" + name.charAt(5));
        for (int i = 0; i <= name.length(); i++) {
            System.out.println(name.charAt(i));
        }
        for (int j = name.length(); j >= 0; j--) {
            System.out.println(name.charAt(j));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

产量

j
a
v
a
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
1
解决办法
1842
查看次数

使用new关键字从同一个包内的类外部调用时,在框架内获取null textarea

我创建了一个框架,里面有一个面板,面板里面有一个textarea.现在我创建了一个构造函数,使框架可见一段时间后,它被设置为不可见.它可见的时间显示了一些消息.

当我在outputDisplay类的main方法中运行构造函数代码时,它会显示文本按钮 屏幕截图的输出调用构造函数在类的主方法中 但是当我通过使用new outputDisplay(String ip,int time)在其他类中调用它时,只有框架出现但内部没有文本.在同一个pakage中的其他类中使用new outputDisplay(String ip,int time)调用时输出的屏幕截图

import java.awt.BorderLayout; 
import java.awt.Color;
import java.awt.Font;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class OutputDisplay {

JFrame frame;
JPanel  panel;
JTextArea area;
Font font;

    OutputDisplay(String ip,int time) throws InterruptedException{
    frame = new JFrame("Warning");
    frame.setLocation(400, 220);
    panel = new JPanel();
    area = new JTextArea();
    font = new Font("Aharoni", Font.BOLD, 16);
    area.setFont(font);
    area.setForeground(Color.RED);
    area.setSize(200, 200);
    int j=0;
    String[] t = {ip}; 
    for(int i=0;i<t.length;i++){
        area.append(t[i]+"\n");
    }//for
    //area.setText(ip);
    panel.add(area);
    panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
    frame.getContentPane().add(BorderLayout.CENTER, panel);
    frame.pack(); …
Run Code Online (Sandbox Code Playgroud)

java swing jframe jtextarea

1
推荐指数
1
解决办法
136
查看次数

在java中重写equals方法但是获得逻辑错误/意外结果

在这个程序中,我试图通过重写equals方法来比较两个引用变量值的字段值----这是代码----

public class D {
int i,j;

 D(int i,int j)
 {
     this.i=i;
     this.j=j;
 }
 public boolean equals(Object f)
 {
    boolean s= (this.i==((D)f).i);
    boolean n= (this.j==((D)f).j);
    return s==n;
 }
}

public class run02 {
 public static void main(String[] args){
 D d=new D(4,5);
 D d1=new D(6,7);
 D d2=new D(8,10);
 System.out.println(d.equals(d1));//comparing reference variable value
 System.out.println(d1.equals(d2));//comparing reference variable value
 System.out.println(d);//printing reference variable memory address
 System.out.println((d==d1));//comparing reference variable memory address
 }
}

Output-true//comparing reference variable value
       true//comparing reference variable value
       firstProg.e@g3h742//memory address
       false//comparing reference variable …
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
171
查看次数

Thread中的异常(java.nullPointerException)

public class Printer {
    static Printer obj =null;
    private Printer(){}
    public static Printer getInstance(){
        if(obj==null){
            Printer pr=new Printer();
        }
        return obj;  
    }
    void print(String msg){
        System.out.println("["+msg);
        try {
            Thread.sleep(1000);
        } catch(InterruptedException c) {
            c.printStackTrace();
        }
        System.out.println("]");
    }
}

class PrintThread implements Runnable {
    Printer p;
    String msg;
    PrintThread(Printer p,String msg) {
        this.p=p;
        this.msg=msg;
    }
    public void run() {
        p.print(msg);//Getting error in this line
    }
}

//Deploying main class
public class Execution {
    public static void main(String[] args) {
        Printer pr=Printer.getInstance(); …
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
3336
查看次数

为什么我在尝试使用void时会在方法中出现语法错误?

public class createArray {
 public static void main(String args[]){
     int[] Array={1,2,3,4};
     String[] SArray= new String[4];
     SArray[0]="Core";
     SArray[1]=" Java";
     SArray[2]=" Is";
     SArray[3]=" Fun";
     int a=Array[2];

     System.out.println("int[] Array Length Is "+ Array.length +" and numbers are " +Array[0]+Array[1]+a+Array[3]);
     System.out.println(SArray[0]+SArray[1]+SArray[2]+SArray[3]);

     public void compareArray(){}
 }
}
Run Code Online (Sandbox Code Playgroud)

我想比较两个字符串但是当我尝试为它创建一个方法时,Java编译器会抛出一个语法错误,其中包含:

令牌"void"上的语法错误

java core

-2
推荐指数
1
解决办法
126
查看次数