私は私のアプリを自動化しています。アプリは解説アプリです。私は3人の選手を選び、それぞれのポジションをクリックしています。ここでは、最初のプレーヤーとそのポジションを選択できますが、セレンの助けを借りて2番目のプレーヤーを選択することはできません。
ここに私のコードです:
//Away team lineups
List total = new ArrayList();
WebElement awayTeam=AppSession.findElementByAccessibilityId("DgViewAwayTeam");
List itemNam =awayTeam.findElements(By.tagName("./*[contains(@LocalizedControlType, 'table')]"));
System.out.println(itemNam.size());//1
for(int b=0;b date = itemNam.get(b).findElements(By.tagName("./*[contains(@LocalizedControlType, 'item')]"));
System.out.println(date.size()); //30
for(int z=1;z< total.size(); currentPlayerIndexFromUI++)
{
String game = total.get(currentPlayerIndexFromUI);// Josh Childress
for(int currentPlayerCellIndexInExcel = 1; currentPlayerCellIndexInExcel < 6; currentPlayerCellIndexInExcel += 2)
{
String nameFomExcel = event.getRow(i).getCell(currentPlayerCellIndexInExcel).getStringCellValue();
String positionInExcel = event.getRow(i).getCell(currentPlayerCellIndexInExcel + 1).getStringCellValue();
WebElement away = AppSession.findElementByAccessibilityId("DgViewAwayTeam");
List date = away.findElements(By.tagName("./*[contains(@LocalizedControlType, 'item')]"));
if(game.equals(nameFomExcel)){ //initially game= Josh Childress , nameFomExcel =Andre Owens
System.out.println(nameFomExcel);
for(int z=0;z
最初の選手を選んでから、F、C、Gをクリックします。
これは私のコンソールに表示されます。
Josh Childress
U
N
F
C
Corsley Edwards
U
N
F
C
G
Andre Owens
U
N
F
これは私の選手リストです。私は配列リストとループでそれを保持しています
Josh Childress
Corsley Edwards
Andre Owens
Brian Scalabrine
DeShawn Stevenson
Jermaine Taylor
私はwinappドライバツールを使用しています、ここではローカライズされたコントロールタイプはサポートされています。
私はinspect.exeからtagnameを取っています、それは最初の行を取っているだけです。行ごとにどのように行を取ることができますか…ここでループはうまく動いていますが、コンソールは見えますがクリックは最初の行第2選手の位置をクリックするように移動していない
ここで問題となるのは、UIから位置の値を取得することです。ここでは、クリックが発生するたびに日付のサイズが0〜30になり、データループを終了してからループを終了した後に移動します。最初のループ、次にzループに戻ります。
zループは0から30まで開始しますか?つまり、2番目の行のクリックが機能していないのはなぜでしょうか…
xpathの代わりに、どのように各行を選択しますか?
ベストアンサー
あなたのコードの私のレビューを確認してください。それはquireエラーが発生する傾向があります。何が問題なのかのインラインコメントを見てください。それらが列挙された順序でそれを読む。
for (int h = 0; h < total.size(); h++) {
String game = total.get(h);
//1. Here you set game = "Josh Childress" (for example)
while (k < 7) {
outLoop:
//6. If we get here after breaking loop we will start from j=1 again
for (int j = 1; j < 6; j += 2) {
//2. Here you start taking values from excel and on the FIRST step you have
//3. event.getRow(i).getCell(j=1).getStringCellValue() = "Josh Childress"
//7. If we will get here after breaking the loop then our condition "game.equals(names)" will stop being true so that we won't get to the if section that is shown below
String names = event.getRow(i).getCell(j).getStringCellValue();
if (game.equals(names)) { //4. This condition will be true on the FIRST step, hence the code inside if will execute
//5. Now assume we're continuing the loop. Lets get back/
}
}
}
}
ここに提案できるアプローチがあります。
for(int currentPlayerIndexFromUI = 0; currentPlayerIndexFromUI < total.size(); currentPlayerIndexFromUI++){
//Here we have items collected on UI and start iterating one by one
//Take the current value from list
String game = total.get(currentPlayerIndexFromUI);
//Now we start iterating cells in excel line
//We know that first player is placed in the cell with index 1
for(int currentPlayerCellIndexInExcel = 1; currentPlayerCellIndexInExcel < 6; currentPlayerCellIndexInExcel += 2){
//Take the next player from excel
String nameFomExcel = event.getRow(i).getCell(currentPlayerCellIndexInExcel).getStringCellValue();
//We also know that the position is alsways next to the player in excel, so we do not need "k". We just shiift player cell +1 to get position
String positionInExcel = event.getRow(i).getCell(currentPlayerCellIndexInExcel + 1).getStringCellValue();
//Now we check the current player from excel equals to the current player from UI list
//If no, just move to the next player from excel (move 2 cells to the right in our "i" line)
if(game.equals(nameFomExcel)){
//If current player in UI is equal to current player from excel, then we take list of date elements for current player in UI(whatever date elements mean)
WebElement away = AppSession.findElementByAccessibilityId("DgViewAwayTeam");
List date = away.findElements(By.tagName("./*[contains(@LocalizedControlType, 'item')]"));
//start iterating by the list of date list
for(int z=0;z
このアプローチは、常に悪い習慣である k
と gotos
を使用しません。