selenium+java chrome自动化测试百度网盘无法定位到上传按钮
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
1.引入库
代码如下(示例):
package webdriver.demo;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.chrome.ChromeDriver;
public class UpFileDemo3 {
public static void main(String[] args) throws InterruptedException{
WebDriver driver=new ChromeDriver();
driver.get("https://pan.baidu.com/");
Thread.sleep(3000);
WebElement user_name=driver.findElement(By.xpath("//*[@id=\"TANGRAM__PSP_4__userName\"]"));
user_name.sendKeys("18651865920");
driver.findElement(By.xpath("//*[@id=\"TANGRAM__PSP_4__password\"]")).sendKeys("heshang82");
Thread.sleep(2000);
driver.findElement(By.id("TANGRAM__PSP_4__submit")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//*[@id=\"wpGuideDialog\"]/div/div/div[1]/div")).click();
Thread.sleep(2000);
String search_handle=driver.getWindowHandle();
WebElement search_click=driver.findElement(By.xpath("/html/body/div[1]/div[3]/div[1]/div[2]/div[4]/div[2]/span[1]/a/form/input"));
Actions action = new Actions(driver);
//action.clickAndHold(search_click).perform();
action.click(search_click).perform();#更换成鼠标操作,问题解决
Thread.sleep(3000);
Runtime rn=Runtime.getRuntime();
try{
String exefile="D://upfile.exe";
rn.exec(exefile);
}catch(Exception e){
System.out.println("Error to run the exe");
}
Thread.sleep(5000);
driver.quit();
}
}
总结
提示:这里对文章进行总结:
Actions action = new Actions(driver);
//action.clickAndHold(search_click).perform();
action.click(search_click).perform();#更换成鼠标操作,问题解决