我有这个代码
File folder = new File("F:\\gals");
File[] listOfFiles = folder.listFiles();
Run Code Online (Sandbox Code Playgroud)
此代码返回文件夹F:\ gals中所有文件的位置数组,我尝试在selenium代码中使用此位置
driver.findElement(By.id(id1)).sendKeys(listOfFiles[1]);
Run Code Online (Sandbox Code Playgroud)
我看到错误
The method sendKeys(CharSequence...) in the type WebElement is not applicable for the arguments (File)
Run Code Online (Sandbox Code Playgroud)
所以我想我必须将listOfFiles []转换为String数组,请告诉我简单的方法.谢谢
我正在学习Java Maven Selenium.我想在Selenium中使用这样的东西implicitlyWait.
这是我的简单代码:
package com.org.learningMaven;
import java.util.concurrent.TimeUnit;
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.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
public class HelloWorldTest {
@Test
public void login() {
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com/");
driver.findElement(By.id("email")).click();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.id("email")).sendKeys("myemail@yahoo.com");
}
private void sendKeys(Keys enter) {
// TODO Auto-generated method stub
}
}
Run Code Online (Sandbox Code Playgroud)
此代码无效.它只需打开Facebook,点击电子邮件字段并输入我的电子邮件ID,而不是在输入我的电子邮件前等待10秒.
在 Selenium 中有很多方法可以选择或聚焦一个元素,例如使用 TAB 键我们可以专注于下一个元素。但是,在 Selenium 中是否有任何方法可以获取当前焦点元素的所有详细信息,例如 id、class、href、text 等?我想专注于帖子的“赞”、“评论”或“分享”按钮https://www.facebook.com/pitbull/photos/a.440436327400.230702.95051637400/10153236215477401/?type=3&theater的 Facebook 页面,但对 Pitbull 没有任何作用我,我尝试了 xpath、class、id,但无法专注于共享按钮。我可以使用 Tab 键专注于分享按钮大约 161 次,但我如何确认聚焦元素是“分享”按钮还是其他东西?;) 这是我的示例代码
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com/");
driver.findElement(By.id("email")).click();
driver.findElement(By.id("email")).sendKeys("myemail@yahoo.com");
driver.switchTo().activeElement().sendKeys(Keys.TAB);
Run Code Online (Sandbox Code Playgroud)
在 TAB 键之后,您知道焦点将从电子邮件字段转到密码字段,那么如何在我的 selenium 代码中获取焦点元素的 id、类或其他详细信息?在我的示例中,它是密码字段。