验证角度1.x输入复选框

时间:2018-05-22 02:59:18

标签: angularjs selenium webdriver

我有以下angular 1.x复选框:

#ifndef LinkedList_hpp
#define LinkedList_hpp

#include <iostream>

template<class T>
struct Node {
    T data;
    Node<T>* next;
};

template<class T>
class SingleLinkedList {
private:
    Node<T>* head, tail;

    SingleLinkedList & operator=(const SingleLinkedList &rhs) {
        head = rhs.head;
        tail = rhs.tail;
        return *this;
    }
public:
    SingleLinkedList() {
        head = nullptr;
        tail = nullptr;
    }

    void createNode(const T& theData) {
        Node<T>* temp = new Node<T>;
        temp->data = theData;
        temp->next = nullptr;
        if(head == nullptr) {
            head = temp;
            tail = temp;
            temp = nullptr;
        }
        else {
            tail->next = temp;
            tail = temp;
        }
    }

    void display() {
        Node<T>* temp = new Node<T>;
        temp = head;
        while(temp != nullptr) {
            std::cout << temp->data << "\t";
            temp = temp->next;
        }
    }

    void insert_start(const T& theData) {
        Node<T>* temp = new Node<T>;
        temp->data = theData;
        temp->next = head;
        head = temp;
    }

    void insert_position(int pos, const T& theData) {
        Node<T>* previous = new Node<T>;
        Node<T>* current = new Node<T>;
        Node<T>* temp = new Node<T>;
        temp = head;
        for(int i  = 1; i < pos; i++) {
            previous = current;
            current = current->next;

        }
        temp->data = theData;
        previous->next = temp;
        temp->next = current;
    }

    void delete_first() {
        Node<T>* temp = new Node<T>;
        temp = head;
        head = head->next;
        delete temp;
    }

    void delete_last() {
        Node<T>* previous = new Node<T>;
        Node<T>* current = new Node<T>;
        current = head;
        while(current->next != nullptr) {
            previous = current;
            current = current->next;
        }
        tail = previous;
        previous->next = nullptr;
        delete current;
    }

    void delete_position(int pos) {
        Node<T>* previous = new Node<T>;
        Node<T>* current = new Node<T>;
        current = head;
        for(int i = 1; i < pos; i++) {
            previous = current;
            current = current->next;
        }
        previous->next = current->next;
    }

    Node<T>* search(Node<T>* head, const T& target) {

    }
};

假设我在jQuery中执行以下操作:

package com.example.xwa.test;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
public class MainActivity extends AppCompatActivity {
private Bitmap bm;
private Canvas canvasBit;
private Paint paintRect;
private Paint paint;
private Handler handler = new Handler();
private Runnable runnable;
final String TAG="TESTTEST";
String path;
int count;
TextView tv;
int i=1;
ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    try {
        UIinital();
        startdraw();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

void UIinital() throws IOException {
    paintRect = new Paint();
    paintRect.setColor(Color.YELLOW);
    paint = new Paint();
    path="car4/img";
    String[] l=getAssets().list(path);
    count=l.length;
    iv=findViewById(R.id.imageView);
    tv=findViewById(R.id.textView);
}

void startdraw()
{
    runnable=new Runnable(){
        public void run() {
            try {
                handler.postDelayed(this, 1000);
                DecimalFormat d=new DecimalFormat("0000");
                String file=path+"/"+d.format(i)+".jpg";
                InputStream in=getAssets().open(file);
                bm= BitmapFactory.decodeStream(in);
                iv.setImageBitmap(bm);
                Log.i(TAG, "run: "+new Integer(i).toString());
                tv.setText("result="+new Integer(i).toString()+"\n");
                i++;
                if(i==count)
                    handler.removeCallbacks(runnable);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    handler.postDelayed(runnable, 0);
}
protected void onStop() {
    super.onStop();
    handler.removeCallbacks(runnable);
}

我总是得到&#34; on&#34;。这与我从webdriver io获得的结果相同。

重申我的问题:

  • 如何从复选框输入中获取值?
  • 如果没有办法解压缩,是否还有其他方法可以从selenium或webdriver中验证这一点io ??

1 个答案:

答案 0 :(得分:0)

对于HTML Chekbox,我们应检查其已检查/未检查状态,而不是其值。无论是选中还是未选中,它的价值都不会改变。

例如   无论您是否检查,<input type="checkbox" name="aa" value="true">$("#fooId").val()都将始终返回"true"

如果支票没有属性value,例如<input type="checkbox" name="aa">,则在致电"on"时,您将始终获得$("#fooId").val()

我们应该检查其检查状态如下:

driver.findElement(By.css('#fooId')).isSelected();