在我的網頁中,我有一個html表格,它包含多個單選按鈕。我想選擇一個單選按鈕。到目前爲止,我能夠從表中找到值,但無法選擇。這是我的代碼:我在語法上遇到錯誤aname.click(); 錯誤是「方法,點擊()是未定義String類型」如何使用java中的Selenium web驅動程序從html表格中選擇字段
import java.io.*;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class SendTxn1 {
static WebDriver d1=null;
public static void main(String[] args) throws IOException, InterruptedException
{
File file1=new File("C:\\Selenium\\IEDriverServer_Win32_2.35.3\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver",file1.getAbsolutePath());
d1= new InternetExplorerDriver();
d1.get("http://10.00.00.107/");
WebElement table_element = d1.findElement(By.id("tblSendMoneyPayoutAgents"));
List<WebElement> tbl_rows=table_element.findElements(By.xpath("id('tblSendMoneyPayoutAgents')/tbody/tr"));
System.out.println("NUMBER OF ROWS IN THIS TABLE = "+tbl_rows.size());
int row_num,col_num;
row_num=1;
col_num=1;
String aname;
for(WebElement trElement : tbl_rows)
{
List<WebElement> tbl_col=trElement.findElements(By.xpath("td"));
for(WebElement tdElement : tbl_col)
{
aname = tdElement.getText();
if(aname.equals("VNM - VN Shop Herat"))
aname.click()l
break;
System.out.println(aname);
col_num++;
}
row_num++;
}
}
}
你能提供你的html代碼嗎? – Amith