我在Stackoverflow上使用Selenium WebDriver看到了很多关于文件上传的问题和解决方案.但是没有一个适用于以下场景.
有人给出了如下解决方案
// assuming driver is a healthy WebDriver instance
WebElement fileInput = driver.findElement(By.name("uploadfile"));
fileInput.sendKeys("C:/path/to/file.jpg");
Run Code Online (Sandbox Code Playgroud)
但我还是找不到窗口句柄我该如何处理?

我正在寻找上述方案的解决方案
请检查以下任何网站
http://www.uploadify.com/demos/
http://www.zamzar.com/
Run Code Online (Sandbox Code Playgroud) 我无法切换到给定示例的模态对话框
http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/showModalDialog2.htm
我不知道如何在模态对话框上获取元素

在日期选择之后,我无法从ajax日历控件中读取日期
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/Calendar/Calendar.aspx
我没有收到任何错误,但我无法从文本框中获取任何值.
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/Calendar/Calendar.aspx");
driver.manage().window().maximize();
//Default calendar:
driver.findElement(By.xpath("//*[@id='ctl00_SampleContent_Date1']")).click();
for(int i=0;i<=5;i++){
for(int j = 0;j<=6;j++){
System.out.print(driver.findElement(By.xpath("//*[@id='ctl00_SampleContent_defaultCalendarExtender_day_"+i+"_"+j+"']")).getText()+"-");
}
System.out.println();
}
driver.findElement(By.xpath("//*[@id='ctl00_SampleContent_defaultCalendarExtender_day_3_4']")).click();
System.out.println(driver.findElement(By.xpath("//*[@id='ctl00_SampleContent_Date1']")).getText());
//Calendar with an associated button:
System.out.println("Calendar with an associated button:------------------------------------------------------");
driver.findElement(By.xpath("//*[@id='ctl00_SampleContent_Image1']")).click();
for(int i=0;i<=5;i++){
for(int j = 0;j<=6;j++){
System.out.print(driver.findElement(By.xpath("//*[@id='ctl00_SampleContent_calendarButtonExtender_day_"+i+"_"+j+"']")).getText()+"-");
}
System.out.println();
}
Thread.sleep(5000L);
driver.findElement(By.xpath("//*[@id='ctl00_SampleContent_Image1']")).click();
driver.findElement(By.xpath("//*[@id='ctl00_SampleContent_calendarButtonExtender_day_3_3']")).click();
System.out.println(driver.findElement(By.xpath("//*[@id='ctl00_SampleContent_Date5']")).getText());
}
Run Code Online (Sandbox Code Playgroud) 我想使用javascript为网页上的所选元素设置属性.
我找到了两种使用javascript设置属性的方法
1
WebDriver driver; // Assigned elsewhere
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementByID('//id of element').setAttribute('attr', '10')");
Run Code Online (Sandbox Code Playgroud)
2
WebElement element = driver.findElement(By.id("foo"));
String contents = (String)((JavascriptExecutor)driver).executeScript("return arguments[0].innerHTML;", element);
Run Code Online (Sandbox Code Playgroud)
但我想将javascript应用于我使用selenium webdriver找到的特定webelement
作为一个例子,我使用selenium webdriver选择一个链接
driver.findElement(By.linkText("Click ME"))
Run Code Online (Sandbox Code Playgroud)
现在我想使用javascript设置此webelement的属性
但我不知道如何将两者结合起来
请帮我找到解决方案
我曾经Driver.switchTo().frame("XXXXX"); 在主页上转到iframe
现在我想回到Main页面使用selenium webdriver进行其他操作
我试图获得窗口句柄
但我无法获得iFrame窗口句柄
我们怎样才能获得使用Selenium WebDriver加载页面的准确时间?
我们使用Thread.sleep
我们使用implicitlyWait
我们使用WebDriverWait
但是如何使用Selenium WebDriver获取加载页面的确切时间?
我想知道WebDriver Wait timeout和implicitlyWait timeout之间的技术差异.
我想在Javascript Prompt中写一些文本.我尝试使用以下代码来运行javascript提示符.如何使用selenium/webdriver填充提示中的值?
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.javascripter.net/faq/prompt.htm#top");
driver.findElement(By.xpath("//input[@value = 'Try it now']")).click();
Alert javascriptprompt = myTestDriver.switchTo().alert();
javascriptprompt.sendKeys("How do I write in a JavaScript prompt message using WebDriver?");
Run Code Online (Sandbox Code Playgroud) 我想知道是什么的好处DefaultSelenium了SeleneseTestCase类?
什么DefaultSelenium是好的?
什么SeleneseTestCase是好的?
selenium ×10
webdriver ×7
java ×4
ajax ×1
alert ×1
file-upload ×1
iframe ×1
javascript ×1
jquery ×1
modal-dialog ×1
selenium-rc ×1
slider ×1