简体   繁体   English

如何使用Selenium Web Driver Java单击具有某些单词作为文本的href

[英]How to click on one href which has certain words as text using selenium web driver java

I am trying to click on href which has neither id nor name. 我试图单击既没有ID也没有名称的href。 It has text as "Proof of Prior Insurance" . 它的文字为“事先保险证明”。 When i tried with xpath 当我尝试使用xpath

"webDriver.findElement(By.xpath("//form*[@name='plaRequiredDocumentsForm']/table[3]/tbody/tr[4]/td/table/tbody/tr/td/table/tbody/tr[2]/td[3]/a")).click()"

it prints "cannot be evaluated or does notresult in a WebElement " in console. 它在控制台中显示“无法评估或未生成WebElement”。

Website code is: 网站代码为:

 <FORM method=post name=plaRequiredDocumentsForm>
    <INPUT name=expVIPCacheKey value=null type=hidden> 
    <INPUT name=wintag value=1411453320424 type=hidden> 
    <DIV style="DISPLAY: none" id=signatureOptionSection>
    <TABLE width=750>
        <TBODY>
            <TR>
                <TD style="PADDING-LEFT: 10pt">
                Signature Option : <INPUT class=bodytext onclick="javascript: setPageDataChangeIndicator(); toggleSignatueStatus(this)" name=signature value=ePad type=radio value2="" value1="">
                    E-Pad &nbsp; <INPUT class=bodytext onclick="javascript: setPageDataChangeIndicator(); toggleSignatueStatus(this)" name=signature value=ink CHECKED type=radio value2="" value1=""> Ink 
                </TD>
            </TR>
        </TBODY>
    </TABLE>
    </DIV>
    <TABLE width=750>
        <TBODY>
            <TR>
                <TD style="TEXT-ALIGN: right; PADDING-LEFT: 5pt; PADDING-RIGHT: 10pt">
                    <A onblur="if (this.children[0]) this.children[0].className='';window.defaultStatus=''" onfocus="if (this.children[0] != null) this.children[0].className='activeButton';window.defaultStatus='button exit    '" onmouseover="window.status='button exit    ';return true;" href="javascript:formExit()">
                    <IMG class=bodytext border=0 align=middle src="../../../images/button_exit.gif"></A>&nbsp; <A onblur="if (this.children[0]) this.children[0].className='';window.defaultStatus=''" onfocus="if (this.children[0] != null) this.children[0].className='activeButton';window.defaultStatus='button image center    '" onmouseover="window.status='button image center    ';return true;" href="javascript:imageCenterSubmit()"><IMG class=bodytext border=0 align=middle src="../../../images/image_center.gif"></A>&nbsp; 
                    <A onblur="if (this.children[0]) this.children[0].className='';window.defaultStatus=''" onfocus="if (this.children[0] != null) this.children[0].className='activeButton';window.defaultStatus='button refresh    '" onmouseover="window.status='button refresh    ';return true;" href="javascript:refresh()">
                    <IMG class=bodytext border=0 align=middle src="../../../images/button_refresh.gif"></A>&nbsp; 
                </TD>
            </TR>
        </TBODY>
    </TABLE>
    <TABLE><BR>
        <TBODY>
            <TR>
                <TD style="PADDING-LEFT: 10pt"><FONT color=red size=2>
                    <B>IMPORTANT:</B> Scanning into the Application of Insurance document type will automatically apply a copy to the Subscription Agreement document type if a Subscription Agreement is required. Each document will be approved independently. </FONT>
                </TD>
            </TR>
        </TBODY>
    </TABLE>
    <TABLE class=surroundingTable border=1 width=750>
        <TBODY>
            <TR>
                <TD colSpan=2>
                    <TABLE class=txnTable>
                        <TBODY>
                            <TR class=sectionHeader>
                                <TD>
                                    <DIV style="FLOAT: left">Household Documents </DIV>
                                    <DIV style="FLOAT: right"><A tabIndex=-1 href="javascript:openHelpTagWindow('/TR/eAgent/Ade/eauto.help.ade?req_page=help&amp;TransType=NN&amp;StateCode=OH&amp;HelpTextId=H02710001')">
                                        <IMG border=0 src="../../../images/icon_question_mark_green_cropped.gif" width=15 height=15></A> 
                                    </DIV>
                                </TD>
                            </TR>
                        </TBODY>
                    </TABLE>
                </TD>
            </TR>
            <TR>
                <TD colSpan=2>
                    <TABLE class=surroundingTable>
                        <TBODY>
                            <TR>
                                <TD>
                                    <TABLE class=txnTable>
                                        <TBODY>
                                            <TR class=columnHeader>
                                                <TD>Household Number</TD>
                                                <TD>Document</TD>
                                                <TD>Status</TD>
                                                <TD>Customer Notified</TD>
                                                <TD>Due Date</TD>
                                                <TD>Signature</TD>
                                                <TD></TD>
                                            </TR>
                                        </TBODY>
                                    </TABLE>
                                </TD>
                            </TR>
                        </TBODY>
                    </TABLE>
                </TD>
            </TR><BR>
            <TR>
                <TD colSpan=2>
                    <TABLE class=txnTable>
                        <TBODY>
                            <TR class=sectionHeader>
                                <TD>
                                    <DIV style="FLOAT: left">Client Documents </DIV>
                                    <DIV style="FLOAT: right">
                                        <A tabIndex=-1 href="javascript:openHelpTagWindow('/TR/help.ade?req_page=help&amp;TransType=NN&amp;StateCode=OH&amp;HelpTextId=H02710002')">
                                        <IMG border=0 src="../../../images/icon_question_mark_green_cropped.gif" width=15 height=15></A> 
                                    </DIV>
                                </TD>
                            </TR>
                        </TBODY>
                    </TABLE>
                </TD>
            </TR>
            <TR>
                <TD colSpan=2>
                    <TABLE class=surroundingTable>
                        <TBODY>
                            <TR>
                                <TD>
                                    <TABLE class=txnTable>
                                        <TBODY>
                                            <TR class=columnHeader>
                                                <TD>Client Name</TD>
                                                <TD>Date of Birth</TD>
                                                <TD>Document</TD>
                                                <TD>Status</TD>
                                                <TD>Customer Notified</TD>
                                                <TD>Due Date</TD>
                                                <TD>Signature</TD>
                                                <TD></TD>
                                            </TR>
                                                <TR class=resultsOff>
                                                    <TD>KARTHICK KAMAL </TD>
                                                    <TD>December 24, 1986</TD>
                                                    <TD>
                                                        <A href="JavaScript:openDocumentWindow('null','A ','A0002','NR','CL',' 734383047','2566332','null','1611745392','734383047','false');">Affinity Discount Documentation </A>
                                                    </TD>
                                                    <TD>Not Received </TD>
                                                    <TD></TD>
                                                    <TD></TD>
                                                    <TD></TD>
                                                    <TD>&nbsp;</TD>
                                                </TR>
                                                <TR class=resultsOff>
                                                    <TD></TD>
                                                    <TD></TD>
                                                    <TD>
                                                        **<A href="JavaScript:openDocumentWindow('null','A ','A0054','NR','CL',' 734383047','2566332','null','1611745392','734383047','false');">Proof of Prior Insurance </A>**
                                                    </TD>
                                                </TR>

Please help me to solve this issue. 请帮我解决这个问题。

use 'driver.findElements(By.cssLocator("td > a"))' method to get the list of elements. 使用'driver.findElements(By.cssLocator(“ td> a”))'方法获取元素列表。

Iterate each element in the said list and get the text in it and compare it to your expected text. 迭代所述列表中的每个元素,并获取其中的文本,并将其与您期望的文本进行比较。 Where it matches that is your element and then you can take an action on it. 它匹配的位置就是您的元素,然后您可以对其进行操作。

Use the following XPath: 使用以下XPath:

//a[contains(text(),'Proof of Prior Insurance')] // a [包含(text(),'事先保险证明')]

暂无
暂无

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

相关问题 如何使用Java和Selenium Web驱动程序单击CTRL + P? - How to click CTRL+P using Java and selenium web driver? 如何使用Java Selenium Web驱动程序强制单击按钮 - How to click on a button with force using java selenium web driver 如何在Java中使用Selenium Web驱动程序单击复选框? - How do I click on checkbox using selenium web driver in Java? 如何在 Java 中使用 selenium web 驱动程序查找突出显示的文本? - How to find the highlighted text using selenium web driver in Java? 如何单击在href中href具有特定子字符串的链接? - How to click a link whose href has a certain substring in Selenium? Selenium Web驱动程序(Java)。 如何在HTML5页面的画布内单击地图内的航点 - Selenium Web Driver (Java) . How to click waypoint inside the map which is canvas in html5 page 在Selenium Web驱动程序中使用Java脚本执行程序单击列表项 - click on list items using java script executor in selenium web driver 如何使用Java在Selenium Web驱动程序中选择并单击单选按钮 - How to select and click on a radio button in selenium web driver with java 如何使用selenium web驱动程序从跨区文本中提取不是正则表达式格式的电子邮件地址? - How to extract an email address which is not in a regular expression format from a span text using selenium web driver? 如何切换到框架并使用Web驱动程序(Selenium-Java)单击弹出窗口? - How do I switch to a Frame and click on the pop up using web driver (Selenium - Java)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM