英文:
sendKeys method throwing an error in selenium like"The method sendKeys(char sequence[] )in the type webelement is not applicable for the string"
问题
>这是我的课程*****
```
package automation;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Test1 {
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:/Users/UMASHANKAR/Downloads/chromedriver_win32/chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.findElement(By.id("userName")).sendKeys("https://sdzclient-kpiregister.azurewebsites.net/");
driver.findElement(By.id("passwords")).sendKeys("Gravity@123");
driver.findElement(By.id("btn-sdz-login")).click();
}
}
```
>在悬停时,sendKeys方法将出现错误,类似于“WebElement类型中的sendKeys(char sequence[])方法不适用于字符串”。
英文:
>this is my class*****
```
package automation;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Test1 {
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:/Users/UMASHANKAR/Downloads/chromedriver_win32/chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.findElement(By.id("userName")).sendKeys("https://sdzclient-kpiregister.azurewebsites.net/");
driver.findElement(By.id("passwords")).sendKeys("Gravity@123");
driver.findElement(By.id("btn-sdz-login")).click();
}
}
```
>on Hover the SendKeys method will get an error like"The method sendKeys(char sequence[] )in the type webelement is not applicable for the string".***
答案1
得分: 0
我不确定,当您说您无法更改编译版本时。您可以根据以下屏幕截图进行更改。
..项目>右键单击>构建路径>配置构建路径>java编译器>
不要忘记在更改编译版本后点击应用。
英文:
I am not sure, when you said you are not able to change compilation version. You can change as per below screen grab.
> ..project>right click>build path>configure build path >java compiler>
Do not forget to click on Apply after changing compilation version.
答案2
得分: 0
当您使用Selenium时,需要遵循以下几个步骤:
//首先,您需要添加Chrome驱动程序路径
System.setProperty("webdriver.chrome.driver", "C:/Users/UMASHANKAR/Downloads/chromedriver_win32/chromedriver.exe");
//其次,您需要初始化WebDriver对象 - 您已经完成了
WebDriver driver = new ChromeDriver();
//第三,您需要告诉WebDriver对象去哪里,加载哪个页面
driver.get("https://sdzclient-kpiregister.azurewebsites.net/");
//以下是登录部分
driver.findElement(By.id("userName")).sendKeys("SET_YOUR_USERNAME_HERE");
driver.findElement(By.id("passwords")).sendKeys("Gravity@123");
driver.findElement(By.id("btn-sdz-login")).click();
您的错误是由于驱动程序不知道要前往哪个页面,但您尝试发送一些按键,而不是驱动页面路径。
英文:
When you are working with Selenium you need to follow a few steps
//first you add your chrome driver path
System.setProperty("webdriver.chrome.driver", "C:/Users/UMASHANKAR/Downloads/chromedriver_win32/chromedriver.exe");
// second you need to initialize the WebDriver object - and you did it
WebDriver driver=new ChromeDriver();
// third you need to tell to the WebDriver object where to go, what page to load
driver.get("https://sdzclient-kpiregister.azurewebsites.net/");
//below is the login part
driver.findElement(By.id("userName")).sendKeys("SET_YOUR_USERNAME_HERE");
driver.findElement(By.id("passwords")).sendKeys("Gravity@123");
driver.findElement(By.id("btn-sdz-login")).click();
your error was throw because the driver didn't know where to go but you tried to send some keys instead of a driving page path
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论