我正在尝试使用Java在Selenium中自动执行Freecharge(" https://www.freecharge.in")网站。登录到我按照以下步骤执行的网站后:
步骤1:点击移动
步骤2:输入手机号码
步骤3:点击后付费单选按钮
步骤4:对于运营商而言相同
步骤5:直接点击继续。
步骤6:在金额文本框中输入值。它不考虑金额并显示零。(需要帮助输入金额)
我写了以下代码:
System.setProperty("webdriver.chrome.driver", "D://chromedriver_win32//chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.navigate().to("https://www.freecharge.in/");
//WAIT
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='_3mvx0']")));
//CLICK ON LOGIN
driver.findElement(By.xpath("//a[@class='_3mvx0']")).click();
//ENTER DETAILS
driver.findElement(By.id("userName")).sendKeys("email_id");
driver.findElement(By.id("password")).sendKeys("password");
//WAIT
Thread.sleep(3000);
//LOGIN
driver.findElement(By.xpath("//button[@class='btn _32_N-']")).click();
//wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Mobile")));
Thread.sleep(3000);
driver.findElement(By.linkText("Mobile")).click();
//ENTER NUMBER TO BE RECHARGE
driver.findElement(By.name("number")).click();
driver.findElement(By.name("number")).sendKeys("9811105989" );
Thread.sleep(10000);
//wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@type='submit']")));
//SELECT PLAN AND OPERATOR
driver.findElement(By.xpath("//div[@class='_1LZRh']/label[2]/span[2]")).click();
Thread.sleep(3000);
Select dropdown = new Select(driver.findElement(By.xpath("//select[@name='operator']")));
dropdown.selectByVisibleText("Vodafone Postpaid");
//WAIT
Thread.sleep(3000);
//PROCEED
driver.findElement(By.xpath("//button[@type='submit']")).click();
Thread.sleep(3000);
//ENTER AMOUNT
driver.findElement(By.xpath("//input[@name='amount']")).sendKeys("400");
driver.findElement(By.xpath("//button[@class='btn _24xNn']")).click();
}
}
答案 0 :(得分:0)
尝试使用后付费单选按钮
driver.findElement(By.xpath(" // DIV [@class =' _1LZRh'] /标签[2] /跨度[2]&#34))。单击( );
答案 1 :(得分:0)
点击单选按钮:
JavascriptExecuter js = (JavascriptExecuter)driver;
js.executeScript("arguments[0].click()", <your radio button web element>);
您可以使用xpath找到该按钮: (// * [@ type =&#39; radio&#39;])[last()]