简体   繁体   English

如何使用Java与网页上的表格进行交互?

[英]How to interact with table on webpage with Java?

I'm trying to make a program for work to automate a spreadsheet that we maintain. 我正在尝试制作一个工作程序来自动化我们维护的电子表格。 The information is on a third party website that we log in to and then scroll through a bunch of pages and then a table is there with all of the info in it. 该信息位于我们登录到的第三方网站上,然后滚动浏览一堆页面,然后有一个包含所有信息的表格。 I used selenium webdriver to open internet explorer, log you in, then navigate you to the correct page but I don't know how to interact with the table. 我使用selenium webdriver打开Internet Explorer,登录后再导航至正确的页面,但我不知道如何与表格进行交互。 When I inspect element in Gooogle chrome, there is no ID or name showing up for the table or any of its cells. 当我检查Gooogle chrome中的元素时,该表或其任何单元格都没有显示ID或名称。 Thanks in advance guys. 在此先感谢大家。

Edit: Here is the HTML Code. 编辑:这是HTML代码。 I put asterisks for sensitive info. 我在星号上输入敏感信息。 The asterisked info is what I need to pull. 星号信息是我需要提取的信息。 I only posted the first quarter or so of the code because it's too many characters but the code just repeats for more rows. 我只发布了代码的第一季度左右,因为它包含太多字符,但是代码重复了更多行。

    <HTML>
<HEAD>
<TITLE>***************</TITLE>
<SCRIPT LANGUAGE="JavaScript">                                                        
function to_SchedForm(theForm) {                                                 
var j = 0;                                                                         
if (theForm.p_chkbox_cnt.value == 1)
{
        if (theForm.p_part_chkbox.checked ){                                             
            ++j;                                                                    
        }                                                                         
}
else{
for (var i = 0; i < theForm.p_part_chkbox.length; i++ ) {                             
        if (theForm.p_part_chkbox[i].checked ){                                             
            ++j;                                                                    
        }                                                                         
}                                                                                 
}
if (j == 0) {                                                                     
    alert("No Part Numbers Selected");                                             
    return false;                                                                      
}                                                                                  
return true;                                                                     
}                                                                                  
function to_MultiSchedForm(theForm) {                                             
var j = 0;                                                                         
var c = 0;                                                                     
var k = 0;                                                                     
for (var i = 0; i < theForm.p_part_chkbox.length; i++ ) {                             
     if (theForm.p_part_chkbox[i].checked ){++k;
         if (theForm.p_mode_chk[i].value != "CR"){                                      
            ++j;                                                                    
         }                                                                         
       }                                                                               
}                                                                                  
if (k == 0) {                                                                     
    alert("No Part Numbers Selected")
    return false;                                                                       
}                                                                                  
if (j != 0 && theForm.ACTION1.value == "multi_order") {                                                                     
    alert("The Multiple Schedule Update option is only available for Schedules that currently have a blank Last Commit value.  Use the Individual Schedules Button to change a commitment Date.")
    return false;                                                                       
}                                                                                  
return true;                                                                     
}                                                                                  
</SCRIPT>                                                                            
</HEAD>
<BODY>
<TABLE  BORDER="0" WIDTH="100%"
                  CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%", VALIGN="top"><IMG SRC="/apps/space/img/PPPS_NEW.jpg" ALT="GM Banner" NAME="PPPS1"></TD>
</TR>
<TR>
<TD width="50%"><HR></TD>
</TR>
</TABLE>
<TABLE  BORDER="0" WIDTH="100%" CELLSPACING="0"
                   CELLPADDING="0">
<TR>
<TD WIDTH="100%", VALIGN="top", ALIGN="center"><IMG SRC="/apps/space/img/priority3.jpg" ALT="Priority Banner" NAME="Priority1"></TD>
</TR>
</TABLE>
<BR>
<CENTER>
<TABLE  WIDTH="100%">
<TR>
<FORM ACTION="Schedule.PrioritySummary" METHOD="POST" NAME="to1_PS_Page">
<INPUT TYPE="hidden" NAME="P_PERSON_ID" VALUE="BZRGJH">
<INPUT TYPE="hidden" NAME="p_mode" VALUE="EDIT">
<INPUT TYPE="hidden" NAME="p_type" VALUE="SCHEDULE">
<INPUT TYPE="hidden" NAME="p_space_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_onum" VALUE="">
<INPUT TYPE="hidden" NAME="p_proc" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcode" VALUE="BL62">
<INPUT TYPE="hidden" NAME="c_sort_one" VALUE="part_number">
<INPUT TYPE="hidden" NAME="c_sort_two" VALUE="priority">
<INPUT TYPE="hidden" NAME="c_sort_three" VALUE="commit_mode">
<INPUT TYPE="hidden" NAME="c_sort_four" VALUE="po_rel_sort">
<INPUT TYPE="hidden" NAME="p_supplier" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcodes_space" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_part" VALUE="">
<INPUT TYPE="hidden" NAME="p_sort_type" VALUE="none">
<TD VALIGN="BOTTOM" ALIGN="LEFT"><FONT FACE="courierNew" SIZE="2"><B> Part #:</B><INPUT TYPE="text" NAME="p_pnum" SIZE="12" MAXLENGTH="12"></FONT><INPUT TYPE="submit" VALUE="GO"></TD>
</FORM>
<FORM ACTION="Schedule.PrioritySummary" METHOD="POST" NAME="to2_PS_Page">
<INPUT TYPE="hidden" NAME="P_PERSON_ID" VALUE="BZRGJH">
<INPUT TYPE="hidden" NAME="p_mode" VALUE="EDIT">
<INPUT TYPE="hidden" NAME="p_type" VALUE="SCHEDULE">
<INPUT TYPE="hidden" NAME="p_space_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_pnum" VALUE="">
<INPUT TYPE="hidden" NAME="p_proc" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcode" VALUE="BL62">
<INPUT TYPE="hidden" NAME="c_sort_one" VALUE="po_rel_sort">
<INPUT TYPE="hidden" NAME="c_sort_two" VALUE="part_number">
<INPUT TYPE="hidden" NAME="c_sort_three" VALUE="priority">
<INPUT TYPE="hidden" NAME="c_sort_four" VALUE="commit_mode">
<INPUT TYPE="hidden" NAME="p_sort_type" VALUE="none">
<INPUT TYPE="hidden" NAME="p_supplier" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcodes_space" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_part" VALUE="">
<TD VALIGN="BOTTOM" ALIGN="LEFT"><FONT FACE="courierNew" SIZE="2"><B> Order #: </B><INPUT TYPE="text" NAME="p_onum" SIZE="12" MAXLENGTH="12"></FONT><INPUT TYPE="submit" VALUE="GO"></TD>
</FORM>
<FORM ACTION="Schedule.PrioritySummary" METHOD="POST"  NAME="to3_PS_Page">
<INPUT TYPE="hidden" NAME="P_PERSON_ID" VALUE="BZRGJH">
<INPUT TYPE="hidden" NAME="p_mode" VALUE="EDIT">
<INPUT TYPE="hidden" NAME="p_type" VALUE="SCHEDULE">
<INPUT TYPE="hidden" NAME="p_space_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_pnum" VALUE="">
<INPUT TYPE="hidden" NAME="p_onum" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcode" VALUE="BL62">
<INPUT TYPE="hidden" NAME="c_sort_one" VALUE="po_rel_sort">
<INPUT TYPE="hidden" NAME="c_sort_two" VALUE="part_number">
<INPUT TYPE="hidden" NAME="c_sort_three" VALUE="priority">
<INPUT TYPE="hidden" NAME="c_sort_four" VALUE="commit_mode">
<INPUT TYPE="hidden" NAME="p_sort_type" VALUE="none">
<INPUT TYPE="hidden" NAME="p_supplier" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcodes_space" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_part" VALUE="">
<TD VALIGN="BOTTOM" ALIGN="LEFT"><FONT FACE="courierNew" SIZE="2"><B><SELECT NAME="p_proc"><OPTION VALUE="0">&lt; Select Processor &gt;<OPTION VALUE="KXH">K.Hr 918040497243         <OPTION VALUE="SJF">S. Fox 586-484-0855       </SELECT></B></FONT><INPUT TYPE="submit" VALUE="GO"></TD>
</FORM>
</TR>
</TABLE>
</CENTER>
<HR>
<CENTER>
<FONT FACE="courierNew" SIZE="2">Mfg. DUNS: <B>178522926</B></FONT>
&nbsp;&nbsp;
<FONT FACE="courierNew" SIZE="2"><B>KAUTEX INC</B></FONT>
&nbsp;&nbsp;
<FONT FACE="courierNew" SIZE="2">Z-code: <B>BL62</B></FONT>
</CENTER>
<CENTER>
<TABLE  WIDTH="100%" BORDER="2" BORDERCOLOR="#00008B">
<TR>
<TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Select One or More</FONT></B></FONT></CENTER></TH><FORM ACTION="Schedule.PrioritySummary" METHOD="POST"  NAME="to4_PS_Page">
<INPUT TYPE="hidden" NAME="P_PERSON_ID" VALUE="BZRGJH">
<INPUT TYPE="hidden" NAME="iv_group" VALUE="">
<INPUT TYPE="hidden" NAME="p_mode" VALUE="EDIT">
<INPUT TYPE="hidden" NAME="p_type" VALUE="SCHEDULE">
<INPUT TYPE="hidden" NAME="p_space_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns_number" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcode" VALUE="BL62">
<INPUT TYPE="hidden" NAME="p_pnum" VALUE="">
<INPUT TYPE="hidden" NAME="p_onum" VALUE="">
<INPUT TYPE="hidden" NAME="p_proc" VALUE="">
<INPUT TYPE="hidden" NAME="p_sort_type" VALUE="part_num">
<INPUT TYPE="hidden" NAME="c_sort_one" VALUE="part_number">
<INPUT TYPE="hidden" NAME="c_sort_two" VALUE="priority">
<INPUT TYPE="hidden" NAME="c_sort_three" VALUE="commit_mode">
<INPUT TYPE="hidden" NAME="c_sort_four" VALUE="po_rel_sort">
<INPUT TYPE="hidden" NAME="p_supplier" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcodes_space" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_part" VALUE="">
<TH  BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><INPUT TYPE="image" NAME="p_img" SRC="/apps/space/img/Part_Number_Button2.gif" border="0"></B></FONT></CENTER></TH></FORM>
<TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="21%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Description</FONT></B></FONT></CENTER></TH><FORM ACTION="Schedule.PrioritySummary" METHOD="POST"  NAME="to5_PS_Page">
<INPUT TYPE="hidden" NAME="P_PERSON_ID" VALUE="BZRGJH">
<INPUT TYPE="hidden" NAME="iv_group" VALUE="">
<INPUT TYPE="hidden" NAME="p_mode" VALUE="EDIT">
<INPUT TYPE="hidden" NAME="p_type" VALUE="SCHEDULE">
<INPUT TYPE="hidden" NAME="p_space_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns_number" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcode" VALUE="BL62">
<INPUT TYPE="hidden" NAME="p_pnum" VALUE="">
<INPUT TYPE="hidden" NAME="p_onum" VALUE="">
<INPUT TYPE="hidden" NAME="p_proc" VALUE="">
<INPUT TYPE="hidden" NAME="p_sort_type" VALUE="ordr_num">
<INPUT TYPE="hidden" NAME="c_sort_one" VALUE="po_rel_sort">
<INPUT TYPE="hidden" NAME="c_sort_two" VALUE="part_number">
<INPUT TYPE="hidden" NAME="c_sort_three" VALUE="priority">
<INPUT TYPE="hidden" NAME="c_sort_four" VALUE="commit_mode">
<INPUT TYPE="hidden" NAME="p_supplier" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcodes_space" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_part" VALUE="">
<TH  BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><INPUT TYPE="image" NAME="p_img" SRC="/apps/space/img/Order_Number_Button2.gif" border="0"></B></FONT></CENTER></TH></FORM>
<TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="7%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Last Commit</FONT></B></FONT></CENTER></TH><FORM ACTION="Schedule.PrioritySummary" METHOD="POST"  NAME="to6_PS_Page">
<INPUT TYPE="hidden" NAME="P_PERSON_ID" VALUE="BZRGJH">
<INPUT TYPE="hidden" NAME="iv_group" VALUE="">
<INPUT TYPE="hidden" NAME="p_mode" VALUE="EDIT">
<INPUT TYPE="hidden" NAME="p_type" VALUE="SCHEDULE">
<INPUT TYPE="hidden" NAME="p_space_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns_number" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcode" VALUE="BL62">
<INPUT TYPE="hidden" NAME="p_pnum" VALUE="">
<INPUT TYPE="hidden" NAME="p_onum" VALUE="">
<INPUT TYPE="hidden" NAME="p_proc" VALUE="">
<INPUT TYPE="hidden" NAME="p_sort_type" VALUE="none">
<INPUT TYPE="hidden" NAME="p_supplier" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcodes_space" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_part" VALUE="">
<TH  BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><INPUT TYPE="image" NAME="p_img" SRC="/apps/space/img/Due_Now_Button2.gif" border="0"></B></FONT></CENTER></TH></FORM>
<TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Due 11/03</FONT></B></FONT></CENTER></TH><TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Due 11/10</FONT></B></FONT></CENTER></TH><TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Due 11/17</FONT></B></FONT></CENTER></TH><TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Due 11/24</FONT></B></FONT></CENTER></TH><TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Future</FONT></B></FONT></CENTER></TH><TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Total</FONT></B></FONT></CENTER></TH><TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">SNR</FONT></B></FONT></CENTER></TH></TR>
<FORM ACTION="Schedule.SchedForm" METHOD="POST" NAME="toSchedForm"onSubmit="if (this.ACTION1.value == 'single_order')
                                    {
                                       if (to_SchedForm(this))
                                       {
                                           return true
                                       }
                                       else
                                       {
                                          return false
                                       }
                                    }
                                    else
                                    {
                                       if (to_MultiSchedForm(this))
                                       {
                                          document.toSchedForm.action=&quot;Schedule.multi_schedform&quot;;return true
                                       }
                                       else
                                       {
                                          return false
                                    }
                                       return false
                                 }">
<INPUT TYPE="hidden" NAME="P_EMS_DIVISION" VALUE="M ">
<INPUT TYPE="hidden" NAME="P_DOC_PREFIX" VALUE="XQ">
<INPUT TYPE="hidden" NAME="P_DOC_NUMBER" VALUE="APHL ">
<INPUT TYPE="hidden" NAME="P_DOCUMENT_TYPE" VALUE="Q">
<INPUT TYPE="hidden" NAME="P_PART_DLS" VALUE="A">
<INPUT TYPE="hidden" NAME="P_PART_PLS" VALUE=" ">
<INPUT TYPE="hidden" NAME="P_PART_NUM" VALUE="23214821">
<INPUT TYPE="hidden" NAME="p_mode_chk" VALUE="CR">
<INPUT TYPE="hidden" NAME="p_chkbox_cnt" VALUE="1">
<TR>
<TD VALIGN="CENTER" ALIGN="CENTER"><B><INPUT TYPE="checkbox" NAME="p_part_chkbox" VALUE="1"></B></TD>
<TD VALIGN="CENTER"
                                         ALIGN="RIGHT"><FONT FACE="CourierNew" SIZE="2"><B>******** </B></FONT></TD>
<TD VALIGN="CENTER"
                                         ALIGN="LEFT"><FONT FACE="courierNew" SIZE="2">TANK ASM - FUEL                                       </FONT></TD>
<TD><FONT FACE="CourierNew" SIZE="2">*******</FONT></TD>
<TD VALIGN="CENTER"
                                     ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>-</B></FONT></TD>
<TD VALIGN="CENTER"
                                            ALIGN="CENTER"><B><FONT COLOR="*****" FACE="courierNew" SIZE="2"></B><B>12</B></FONT></TD>
<TD VALIGN="CENTER"
                                            ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
                                         ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
                                         ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
                                         ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
                                         ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
                                         ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>****</B></FONT></TD>
<TD VALIGN="CENTER"
                                         ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>-</B></FONT></TD>
</TR>
<INPUT TYPE="hidden" NAME="P_EMS_DIVISION" VALUE="M ">
<INPUT TYPE="hidden" NAME="P_DOC_PREFIX" VALUE="XQ">
<INPUT TYPE="hidden" NAME="P_DOC_NUMBER" VALUE="APHL ">
<INPUT TYPE="hidden" NAME="P_DOCUMENT_TYPE" VALUE="Q">
<INPUT TYPE="hidden" NAME="P_PART_DLS" VALUE="A">
<INPUT TYPE="hidden" NAME="P_PART_PLS" VALUE=" ">
<INPUT TYPE="hidden" NAME="P_PART_NUM" VALUE="***********">
<INPUT TYPE="hidden" NAME="p_mode_chk" VALUE="CR">
<INPUT TYPE="hidden" NAME="p_chkbox_cnt" VALUE="2">
<TR>
<TD VALIGN="CENTER" ALIGN="CENTER"><B><INPUT TYPE="checkbox" NAME="p_part_chkbox" VALUE="2"></B></TD>
<TD VALIGN="CENTER"
                                         ALIGN="RIGHT"><FONT FACE="CourierNew" SIZE="2"><B>******** </B></FONT></TD>
<TD VALIGN="CENTER"
                                         ALIGN="LEFT"><FONT FACE="courierNew" SIZE="2">TANK ASM - FUEL                                       </FONT></TD>
<TD><FONT FACE="CourierNew" SIZE="2">J1UJ3  -000</FONT></TD>
<TD VALIGN="CENTER"
                                     ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>-</B></FONT></TD>
<TD VALIGN="CENTER"
                                            ALIGN="CENTER"><B><FONT COLOR="FF0000" FACE="courierNew" SIZE="2"></B><B>*****</B></FONT></TD>
<TD VALIGN="CENTER"
                                            ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
                                         ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
                                         ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
                                         ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
                                         ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
                                         ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>********</B></FONT></TD>
<TD VALIGN="CENTER"
                                         ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>-</B></FONT></TD>

Okay, so its useful to know that you can find any element by its element id, eg driver.findElement(By.id("table")) . 好的,因此知道您可以通过其元素ID查找任何元素非常有用,例如driver.findElement(By.id("table")) This will give you the first element of that type. 这将为您提供该类型的第一个元素。 However, you have multiple tables, so you'll need to find a way to get the right table. 但是,您有多个表,因此需要找到一种获取正确表的方法。

There are different ways to do this, but they'll usually revolve around some individual characteristic of your target. 有不同的方法可以执行此操作,但是它们通常围绕目标的某些个性特征。 In this case the obvious example for me is that it contains this: 在这种情况下,对我来说显而易见的示例是它包含以下内容:

<TR>
<TD WIDTH="100%", VALIGN="top", ALIGN="center"><IMG SRC="/apps/space/img/priority3.jpg" ALT="Priority Banner" NAME="Priority1"></TD>
</TR>

Though this means we're looking down into children levels (makes things a little more complicated). 尽管这意味着我们正在关注儿童级别(这使事情变得有些复杂)。 What we can do is look for that particular element and then find its parent table via xpath like in this xpath tutorial . 我们可以做的是查找该特定元素,然后像本xpath教程中那样通过xpath查找其父表。

  1. So, to find the image element we simply use: 因此,要查找图像元素,我们只需使用:

WebElement imageElement = driver.findElement(By.name("Priority1"));

This gives us the image element. 这给了我们图像元素。

  1. To find the table containing said imageElement we then use: 为了找到包含所述imageElement的表,我们使用:

WebElement tableElement = imageElement.findElement(By.xpath(//ancestor::table));

This should find the ancestor element that is a table containing the priority1 image. 这应该找到祖先元素,该元素是包含priority1图像的表。

I suggest you have a look at how x-path works. 我建议您看看x路径的工作原理。 Its very useful, but sometimes it does require a little tinkering (especially if a web page changes). 它非常有用,但有时确实需要进行一些修改(尤其是在网页更改的情况下)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM