在selenium中使用java选择复选框值

时间:2016-12-23 17:28:24

标签: java selenium checkbox

我需要从给定的附件中选择一个复选框值。

问题在于它不是这样设计的,我可以选择特定值的id。

我想在Material block下找到Profile fbProfile = Profile.getCurrentProfile(); AccessTokenTracker accessTokenTracker = new AccessTokenTracker() { @Override protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) { if (currentAccessToken == null) { Log.d(TAG, "onLogout catched"); deleteContact();//This is my code } } }; if (fbProfile == null) { Log.d(TAG, "NOT logged in"); callbackManager = CallbackManager.Factory.create(); LoginButton loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setReadPermissions("email"); // Callback registration loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { Log.d(TAG, "onSuccess login Facebook"); GraphRequest request = GraphRequest.newMeRequest( AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { FacebookSdk.setIsDebugEnabled(true); FacebookSdk.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); Log.d(TAG, "AccessToken.getCurrentAccessToken() " + AccessToken.getCurrentAccessToken().toString()); Profile profile = Profile.getCurrentProfile(); Log.d(TAG, "Current profile: " + profile); if (profile != null) { Log.d(TAG, String.format("id = %s; name = %s; lastName = %s; uri = %s", profile.getId(), profile.getFirstName(), profile.getLastName(), profile.getProfilePictureUri(50, 60))); name = String.format("%s %s",profile.getFirstName(),profile.getLastName()); fbid = profile.getId(); pushNewContact();//This is my code } } }); request.executeAsync(); } @Override public void onCancel() { Log.d(TAG, "onCancel"); } @Override public void onError(FacebookException e) { Log.e(TAG, "onError", e); } }); } else { Log.d(TAG, "Logged with " + fbProfile.getName()); fbid = fbProfile.getId(); } accessTokenTracker.startTracking(); 个元素并选择值cotton。

我对selenium很新,我尝试首先使用以下代码显示元素:

List

但它不断给出如下例外:

  

线程中的异常&#34; main&#34; java.lang.ClassCastException:   java.util.ArrayList无法强制转换为org.openqa.selenium.WebElement     在   com.jahira.addtocart.searchBedsheets.filterBedsheets(searchBedsheets.java:57)     在   com.jahira.addtocart.searchBedsheets.main(searchBedsheets.java:121)

请告诉我我正在做的错误,并帮助我们选择复选框的价值表单。

1 个答案:

答案 0 :(得分:0)

尝试以下代码段

List <WebElement> materialList = driver.findElements(By.id("ref_3248233031")); 
For(WebElement elem:materialList ){
   if(elem.getAttribute("value").equalsIgnoreCase("cotton"){
       elem.click;
       break;
      }
}