0

私の仕事は、右クリックして、HTMLテーブルのドロップダウンメニューから1つのオプションを選択することです。

このために私は2つのことで助けが必要です:

  1. セレンを使用して、テーブル内の一意のセルを識別する方法は?

  2. 識別されたセルを右クリックする方法は?

このアプリケーションはIE専用に開発されており、表のサンプルコードは次のとおりです。

table id="ctl00_ContentPlaceHolder1_dgvPatientList" class="grid" cellspacing="0" cellpadding="2" border="1" style="width:96%;border-collapse:collapse;" rules="all">

![これはHTMLテーブルのコードです][1]助けてくれてありがとう。

4

2 に答える 2

1

あなたの最初の静止を考慮して、ここで議論されました(セレンを使用したテーブルセルの操作)コードが提供されました(コードの例では、テーブルのすべてのセルからテキストを取得します):

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class WebTableExample 
{

    public static void main(String[] args) 
    {
        WebDriver driver = new InternetExplorerDriver();
        driver.get("http://localhost/test/test.html");


        WebElement table_element = driver.findElement(By.id("testTable"));
        List<WebElement> tr_collection=table_element.findElements(By.xpath("id('testTable')/tbody/tr"));

        System.out.println("NUMBER OF ROWS IN THIS TABLE = "+tr_collection.size());
        int row_num,col_num;
        row_num=1;
        for(WebElement trElement : tr_collection)
        {
            List<WebElement> td_collection=trElement.findElements(By.xpath("td"));
            System.out.println("NUMBER OF COLUMNS="+td_collection.size());
            col_num=1;
            for(WebElement tdElement : td_collection)
            {
                System.out.println("row # "+row_num+", col # "+col_num+ "text="+tdElement.getText());
                col_num++;
            }
            row_num++;
        }    
    }       
}

2番目の質問を考慮してください。ちょっとした回避策を調査しました。可能性の 1 つ:

selenium.mouseDownRight(locator);
  selenium.mouseUpRight(locator);

別の方法:

WebElement elem = driver.findElement(By.xpath(".blablabla..")); //the element we want to //right click on
new Actions(driver).contextClick(elem).perform();

別の方法は、javascript を使用することです。

したがって、テーブル セルを webElement として取得します。そして、それを右クリックします。それがうまくいくことを願っています。

于 2012-10-09T14:35:30.603 に答える