あなたの最初の静止を考慮して、ここで議論されました(セレンを使用したテーブルセルの操作)コードが提供されました(コードの例では、テーブルのすべてのセルからテキストを取得します):
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 として取得します。そして、それを右クリックします。それがうまくいくことを願っています。