我正在尝试执行http://site21.way2sms.com的自动化代码,
错误在第3&从最后一行开始 //错误代码
driver.findElement(By.xpath("//input[@name='mobile']")).sendKeys("xxxxxxxxx");
driver.findElement(By.xpath("//*[contains(@placeholder, 'Type your message ')]")).sendKeys("call me urgently,need to talk");
尝试代码: -
package testpack;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
public class Test6 {
public static void main(String[] args) throws InterruptedException
{
// Run Chromedriver.exe to get chrome browser
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
ChromeDriver driver=new ChromeDriver();
Thread.sleep(5000);
//Launch site
driver.get("http://site21.way2sms.com/content/index.html");
Thread.sleep(5000);
driver.findElement(By.name("username")).sendKeys("xxxxxxxxxx");
driver.findElement(By.name("password")).sendKeys("xxxx");
Thread.sleep(5000);
driver.findElement(By.id("loginBTN")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//*[text()='Send SMS']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@name='mobile']")).sendKeys("xxxxxxxxxx");
driver.findElement(By.xpath("//*[contains(@placeholder, 'Type your message ')]")).sendKeys("Call me urgently, need to talk");
Thread.sleep(5000);
driver.findElement(By.name("Send")).click();
答案 0 :(得分:0)
请尝试使用以下代码
driver.switchTo().frame(driver.findElement(By.id("frame")));
driver.findElementByXPath("//input[contains(@id,'mobile')]").sendKeys("xxxxxxxx");
driver.findElementByXPath("//*[@*='message'] | //*[@*='Type your message here or use SMS greetings']").sendKeys("test smsm");
driver.findElementByXPath("//*[@*='Send'] | //*[@*='return sendMessage();']").click();
答案 1 :(得分:0)
您可以使用以下代码:
driver.switchTo().frame("frame");
driver.findElement(By.id("mobile")).sendKeys("xxxxxxxxx");
driver.findElement(By.xpath("//*[contains(@placeholder, 'Type your message ')]")).sendKeys("Call me urgently, need to talk");
Thread.sleep(5000);
driver.findElement(By.name("Send")).click();
driver.switchTo().defaultContent();
您的代码很好,但您错过了切换到相框。