如果重复,请选择specifec'span'标签

时间:2017-08-09 02:55:23

标签: selenium webdriver python-3.5

我的页面中有两个span标签 我尝试了那种方法

web.find_element_by_xpath('//span[@class="_54nh"]').click()

它错误的跨度不是我想要的 所以我需要选择与另一个标签不同的“删除”文本 有html源

▼<span>
  <span class="_54nh">
</span>

那我需要选择

  ▼<span>
    <span class="_54nh">Delete</span>
  </span>

区别在于“删除”字样

1 个答案:

答案 0 :(得分:1)

您可以通过在搜索条件中添加预期文本来优化MainActivity extends BaseActivityLocation implements NavigationView.OnNavigationItemSelectedListener, SearchView.OnQueryTextListener, SearchView.OnSuggestionListener { @Override public boolean onQueryTextSubmit(String query) { for(Marker m : list) { System.out.println(list+m.getSnippet() + m.getTitle() + m.getPosition() + " snippet"); if(m.getSnippet().toLowerCase().equals(query)) { Toast.makeText(this, "You searched for: " + query , Toast.LENGTH_SHORT).show(); mMapFragment.animateCamera(CameraUpdateFactory.newLatLngZoom(m.getPosition(), 9.0f)); break; // stop the loop } } return false; } public void onResponse(Call<JsonElement> call, Response<JsonElement> response) { // success response if (response.body().isJsonArray()) { JsonArray objectWhichYouNeed = response.body().getAsJsonArray(); System.out.println(objectWhichYouNeed + " Object"); for (int i = 0; i < response.body().getAsJsonArray().size(); i++) { JsonElement plate_num_array = response.body().getAsJsonArray().get(i); JsonObject plate_num_obj = plate_num_array.getAsJsonObject(); String plate_n = plate_num_obj.get("plate_num").toString(); String plate_nString = plate_n; plate_nString = plate_nString.replace("\"", ""); String plate_num = String.valueOf(plate_nString); JsonElement lat_array = response.body().getAsJsonArray().get(i); JsonObject lat_obj = lat_array.getAsJsonObject(); String lati = lat_obj.get("lat").toString(); String latiString = lati; latiString = latiString.replace("\"", ""); String lat = String.valueOf(latiString); JsonElement lng_array = response.body().getAsJsonArray().get(i); JsonObject lng_obj = lng_array.getAsJsonObject(); String longi = lng_obj.get("lng").toString(); String longiString = longi; longiString = longiString.replace("\"", ""); String lng = String.valueOf(longiString); createMarker(d, d2, plate_num); } ,如下所示:

 public MarkerOptions createMarker(Double latitude, final Double longitude, String Plate_num) {
    BitmapDescriptor image = BitmapDescriptorFactory.fromResource(R.drawable.bus);

    list = new ArrayList<>();

    System.out.print(list + " Snippp");

   /*  mMapFragment.addMarker(new MarkerOptions()
            .position(new LatLng(latitude, longitude))
            .anchor(0.5f, 0.5f)
            .title("Plate No.")
            .snippet(Plate_num)
            .icon(image));*/

    mMapFragment.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {
            marker.hideInfoWindow();
        }
    });

    mMapFragment.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 9.0f));

    mMapFragment.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(final Marker marker) {
            vm = new VehicleMap();

            vm.setSnippet(marker.getSnippet());
            vm.setPlate_num(marker.getSnippet());

            latitudeG = marker.getPosition().latitude;
            longitudeG = marker.getPosition().longitude;

            marker.showInfoWindow();

            BottomSheetDialogFragment bottomSheetDialogFragment = new BottomSheetModalFragment(activity);
            bottomSheetDialogFragment.show(getFragmentManager(), bottomSheetDialogFragment.getTag());

            return true;
        }
    });

    return new MarkerOptions()
            .position(new LatLng(latitude, longitude))
            .title("Plate No.")
            .snippet(Plate_num)
            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));

}