无法从selenium中的日,月和年下拉选项的下拉列表中选择值

时间:2017-06-27 06:15:59

标签: java selenium

enter image description here

在boohoo电子商务网站上进行注册时,我无法从下拉日期,月份和年份中选择价值,因此我无法采取进一步措施。

could you please help me to resolve this issue

site:http://www.boohoo.com/

steps1 :open URL of Boohoo, 

Step 2: Go to User Icon then click on registeration link

==============================================
public class Boohoo {
      WebDriver driver;

      @BeforeMethod
      public void beforeMethod() {
      System.setProperty("webdriver.chrome.driver","C:\\Chrome\\chromedriver.exe");
      ChromeOptions options = new ChromeOptions();

      Map<String, Object> prefs = new HashMap<String, Object>();
      prefs.put("credentials_enable_service", false);
      prefs.put("password_manager_enabled", false); 
      options.setExperimentalOption("prefs", prefs);
      options.addArguments("start-maximized");
      options.addArguments("disable-infobars");
      driver = new ChromeDriver(options);

 }  
      @Test(priority=3)
  public void BoohooURLverify() {
     driver.get("http://www.boohoo.com/");
     String Title=driver.getTitle();
     if(Title.endsWith("http://www.boohoo.com/"))
     {
         System.out.println("Url is verifedand is correct");
     }
     else

     System.out.println("Incorrect URl is opened");
     driver.quit();

  }
      @Test(priority=1)
      public void BohooRegisteration() {
         driver.get("http://www.boohoo.com/");
         Actions Action=new Actions(driver);
         WebElement User_link=driver.findElement(By.xpath(".//*[@id='wrapper']/div[4]/div[1]/div/ul/li[2]/div/span"));
        WebElement Register_link=driver.findElement(By.xpath(".//*[@id='wrapper']/div[4]/div[1]/div/ul/li[2]/div/div/div/a[2]"));
        Action.moveToElement(User_link).moveToElement(Register_link).click().build().perform();
        WebElement Register_page_title=driver.findElement(By.xpath(".//*[@id='main']/div/h1")) ;
         String Register_page_Title=Register_page_title.getText();
         System.out.println(Register_page_Title);
         if (Register_page_Title=="Create Account")
         {
             System.out.println("Page Title is correct");
         }
         else
         {
             System.out.println("Incorrect title of registration page");
         }
         Select drpdwn1=new Select(driver.findElement(By.xpath(".//*[@id='dwfrm_profile_customer_title']")));
         drpdwn1.selectByVisibleText("Miss");
         driver.findElement(By.xpath(".//*[@id='dwfrm_profile_customer_firstname']")).sendKeys("Rashmi");
         driver.findElement(By.xpath(".//*[@id='dwfrm_profile_customer_lastname']")).sendKeys("Patil");
         Select drpdwn2=new Select(driver.findElement(By.xpath(".//*[@id='dwfrm_profile_customer_dayofbirth']")));

        drpdwn1.selectByVisibleText("05");
         drpdwn1.selectByIndex(02);
         Select drpdwn3=new Select(driver.findElement(By.xpath(".//*[@id='dwfrm_profile_customer_monthofbirth']")));
         drpdwn1.selectByVisibleText("05");
         Select drpdwn4=new Select(driver.findElement(By.xpath(".//*[@id='dwfrm_profile_customer_yearofbirth']")));
         drpdwn1.selectByVisibleText("1990");
         Select drpdwn5=new Select(driver.findElement(By.xpath(".//*[@id='dwfrm_profile_customer_gender']")));
         drpdwn1.selectByVisibleText("Female");
         driver.findElement(By.id("dwfrm_profile_customer_email")).sendKeys("vaishali.1990@rediffmail.com");
         driver.findElement(By.id("dwfrm_profile_customer_emailconfirm")).sendKeys("vaishali.1990@rediffmail.com");
         driver.findElement(By.id("dwfrm_profile_login_password_d0dazcxwlbzi")).sendKeys("vaishali.1990@rediffmail.com");
         driver.findElement(By.id("dwfrm_profile_login_passwordconfirm_d0ehbfaagjuv")).sendKeys("vaishali.1990@rediffmail.com");
        driver.findElement(By.xpath(".//*[@id='RegistrationForm']/fieldset[2]/div[9]/button")).click();
        System.out.println("Account should be created sucessfully");
         driver.close();
      }
}

============================================== <登记/> 错误消息:在它下面是错误

org.openqa.selenium.NoSuchElementException: Cannot locate element with text: 05
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
System info: host: 'D90ZC6Q1', ip: '192.168.163.235', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_92'
Driver info: driver.version: unknown
    at org.openqa.selenium.support.ui.Select.selectByVisibleText(Select.java:150)
    at ecommerce_pack1.Boohoo.BohooRegisteration(Boohoo.java:82)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:774)
    at org.testng.TestRunner.run(TestRunner.java:624)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
    at org.testng.SuiteRunner.run(SuiteRunner.java:261)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)


===============================================
    Default test
    Tests run: 2, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 2, Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@1b40d5f0: 243 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@35851384: 56 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@1ae369b7: 46 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 65 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@d7b1517: 8 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@2b80d80f: 111 ms

3 个答案:

答案 0 :(得分:0)

以下是您的问题的答案:

打开网址https://www.boohoo.com并浏览到https://www.boohoo.com/register页后,以下代码块会选择Day05Month为{{ 1}}和05Year

1990

如果这回答你的问题,请告诉我。

答案 1 :(得分:0)

你在程序中犯了一些错误。您使用了错误的下拉列表来发送值。

您的代码行

     Select drpdwn2=new Select(driver.findElement(By.xpath(".//*[@id='dwfrm_profile_customer_dayofbirth']")));
     drpdwn1.selectByVisibleText("05");
     drpdwn1.selectByIndex(02);

修改后的代码

     Select drpdwn2=new Select(driver.findElement(By.xpath(".//*[@id='dwfrm_profile_customer_dayofbirth']")));
     drpdwn2.selectByVisibleText("05");

答案 2 :(得分:0)

如果所有选择方法都不起作用,您可以单击下拉箭头将其打开,然后单击By.linkText(&#34; 05&#34;)。不像其他解决方案那样优雅,但应该做好工作。