2016-04-19 6 views
1

Как я могу щелкнуть ссылку, выделенную в прикрепленном изображении, используя библиотеку python selenium, я пробовал все (большинство попыток показано ниже), но все не работают.Нажмите ссылку, используя Selenium Python Library

примечание в прилагаемом изображении дерево элементов.

enter image description here

код страницы (ссылка на вопрос является последним звеном в коде ниже:

<HEAD> 
<TITLE> Constructor Self Service</TITLE> 
</HEAD> 


<script type="text/javascript"> 
...... 
</script> 

<link rel="stylesheet" 
href="/global/res/themes/corporate/css/style3.css" 
type="text/css"> 
<script type="text/javascript" 
src="/global/res/javascript/horizontal_subsection_HM_Loader.js"></script> 

<link rel=stylesheet href="css/tcss.css" TYPE="text/css"> 
<script type="text/javascript" src="arrays/aaclib.js"></script> 
<script type="text/javascript" src="arrays/csslib.js"></script> 




<table cellspacing=0 cellpadding=0 border=0 width="100%" height="100%" > 
<tr><td valign="top"> 
<form name="mainForm" action="/TCSSPRODapp/Controller" 
method="POST" onsubmit="return false;"> 
<input type="hidden" name="command"> 
<input type="hidden" name="page"> 
<input type="hidden" name="menuIndex"> 
<input type="hidden" name="submitted" value="false"> 
<input type="hidden" name="pageToken" 
value=679> 
<input type="hidden" name="isInternal" 
value=false> 



<body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginwidth="0" 
marginheight="0"> 
<!--begin global header--><!--Don't place any other HTML code on this line!!--> 
<script language="javascript" src="/global/javascript/head_array.js" type="text/javascript"></script> 
<script language="javascript" type="text/javascript"> 
var v6=0; 
if(typeof hmVisi!="undefined"&&typeof sectionId!="undefined")v6=1; 
if(v6)document.write('</head><body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="TEL_onLoad()">'); 

function alertUser() { 
    if(confirm("Warning: Any unsaved data would be lost.\rDo you want to Continue?")) { 
     return true; 
    } else { 
     return false; 
    } 
} 

</script> 
<link rel="stylesheet" href="/global/css/gwy_hed.css" type="text/css"> 
<a name="top"></a> 
<table width="100%" cellpadding="0" cellspacing="0" border="0"> 
    <tr> 
     <td rowspan="4" valign="top"><a href="http://telstra.com/?tR=1"><img src="/global/images/telstra_logo2.gif" width="85" height="85" border="0" alt="telstra.com"></a></td> 
     <td align="right" class="ap1"><span class="hd1"><a href="javascript:toggleAccessibility()"><img src="/global/images/sin.gif" width="1" height="37" border="0" alt="press enter now to toggle the accessibile text mode of this page" align="absmiddle"></a> 
     <a href="http://telstra.com/?tR=1">Telstra Homepage</a> | <a href="http://www.telstra.com.au/contact/?tR=1">Contact Us</a> | <a href="http://search.telstra.com/">Search</a><img src="/global/images/sin.gif" width="12" height="1" alt=""></span></td> 
     <td width="50%" class="ap1"><img src="/global/images/sin.gif" width="1" height="57" alt=""></td> 
    </tr> 
    <tr class="hd3"> 
    <!--<td><img src="/global/images/sin.gif" width="500" height="2" alt=""></td>--> 
     <td colspan=50 width="100%"><img src="/global/images/sin.gif" width="100" height="2" alt=""></td> 
     <td><img src="/global/images/sin.gif" width="1" height="2" alt=""></td> 
    </tr> 
    <tr> 
     <td align="right"><img src="/global/images/gwy_grad.gif" width="328" height="6" alt=""></td> 
     <td class="hd4"><img src="/global/images/sin.gif" width="1" height="1" alt=""></td> 
    </tr> 
    <tr> 
     <td colspan=2 class="hd5" nowrap><NOBR> 
    <table cellpadding=1 cellspacing=1 border=0> 
    <tr> 
    <!-- AMCO-WORKFLOW:MODIFY:START --> 
    <!--<td rowspan=3 class="hd5" nowrap><img src="/global/images/sin.gif" width="15" height="10" alt="" align="top">Telstra Contractor Self Service<img src="/global/images/sin.gif" width="25" height="1" alt="" align="top"></td>--> 
    <td rowspan=4 class="hd5" nowrap><img src="/global/images/sin.gif" width="5" height="10" alt="" align="top">Telstra Constructor Self Service<img src="/global/images/sin.gif" width="5" height="1" alt="" align="top"></td> 
    <!-- AMCO-WORKFLOW:MODIFY:END --> 
    <TD nowrap><img src="/global/images/sin.gif" width="10" height="12"></TD> 
    <TD nowrap></TD> 
    <TD nowrap></TD> 
    <!-- AMCO-WORKFLOW:ADD:START --> 
    <!--5.14.01 Anand Changes: start--> 
    <!--<TD nowrap></TD>--> 
    <!--5.14.01 Anand Changes: start--> 
    <!-- AMCO-WORKFLOW:ADD:END --> 
    <!--5.14.01 Anand Changes: start--> 
    </tr> 
    <tr style="background-color:#99ccff;"> 
    <!-- AMCO-WORKFLOW:ADD:START --> 

    <TD class=button> 
    <a class=button style="text-decoration:none" 
    title="AMCO" 
    href="javascript:doCommand('doWidebandWorkSummary')" 
    onmousemove="window.status='View Work Summary'" 
    onmouseout="window.status=window.defaultStatus"> 
    AMCO</a> 
    </TD> 

    <!-- AMCO-WORKFLOW:ADD:END --> 
    <TD nowrap style="background-color:#ffffff;"></TD> 
    <TD class=button nowrap> 
    <a class=button style="text-decoration:none" 
    title="View Inbox" 
    href="javascript:doCommand('doInboxStat')" 
    onmousemove="window.status='View Inbox'" 
    onmouseout="window.status=window.defaultStatus"> 
    <NOBR>Inbox 0</NOBR></a> 
    </TD> 
    <TD class=button> 
    <a class=button style="text-decoration:none" 
    title="View Outbox" 
    href="javascript:doCommand('doOutboxStat')" 
    onmousemove="window.status='View Outbox'" 
    onmouseout="window.status=window.defaultStatus"> 
    <NOBR>Outbox 0</NOBR></a> 
    </TD> 

    <!--Start : IPaC Stage II Drop1 : Refresh button added--> 
    <TD class=button> 
    <a class=button style="text-decoration:none" 
    title="Refresh Inbox and Outbox" 
    href="javascript:doCommand('doInboxOutboxRefresh')" 
    onmousemove="window.status='Refresh Inbox and Outbox'" 
    onmouseout="window.status=window.defaultStatus" 
    onclick="return alertUser()"> 
    <NOBR>Refresh</NOBR></a> 
    </TD> 
    <!--End : IPaC Stage II Drop1--> 

    <TD nowrap style="background-color:#ffffff;"></TD> 
    <TD class=button nowrap> 
    <a class=button style="text-decoration:none" 
    title="Display TCSS help" 
    href="javascript:loadHelpWindow()" 
    onmousemove="window.status='Display TCSS help'" 
    onmouseout="window.status=window.defaultStatus"> 
    <NOBR>Help</NOBR></a> 
    </TD> 
     <!-- AMCO-WORKFLOW:ADD:START --> 
    <!--5.14.01 Anand Changes: start--> 
<!--<TD nowrap width="151" style="background-color:#ffffff;"></TD>--> 
     <!--5.14.01 Anand Changes: end--> 
    </tr> 
    <tr> 
    <TD nowrap><img src="/global/images/sin.gif" width="38" height="12"></TD> 
    <!--Start : IPaC Stage II Drop1 : Display message if refresh didnt occur--> 
    <TD nowrap style="background-color:#ffffff;"></TD> 

     <TD nowrap><img src="/global/images/sin.gif" width="38" height="12"></TD> 
     <TD nowrap style="background-color:#ffffff;"></TD></tr> 
     <tr> 
     <TD nowrap><img src="/global/images/sin.gif" width="38" height="12"></TD> 
     <TD nowrap style="background-color:#ffffff;"></TD> 
     </tr> 
     <!--<TD nowrap></TD>--> 
     <!--<TD nowrap></TD>--> 
     <!-- AMCO-WORKFLOW:ADD:START --> 
     <!--<TD nowrap></TD>--> 
     <!-- AMCO-WORKFLOW:ADD:END --> 

    <!--End : IPaC Stage II Drop1--> 
    </tr> 
    </table> 

    </NOBR> 
    </td> 

    </tr> 
</table> 
<script language="javascript" type="text/javascript"> 

<!--5.14.01 Anand Changes: changed from 100% to 15 % start--> 
var s='<table width="50%" cellpadding="0" cellspacing="0" border="0"><tr><td class="siteletTitleTab"><img src="/global/images/sin.gif" width="1" height="3" alt=""></td></tr></table>'; 
<!--5.14.01 Anand Changes: changed from 100% to 15 % end--> 
if(v6)document.write(s); 
</script> 
<!--end global header--><!--Don't place any other HTML code on this line!!--> 





<table width="100%" border="0" cellspacing="0" cellpadding="0"> 
<tr class=""> 
    <td width="100%" rowspan="2" align=right> 

    </td> 
<TD> 
    <INPUT type="hidden" name="internalConstructor" size=10 value="false"> </TD> 
</tr> 
</table> 

<table border=0 cellspacing=0 cellpadding=0 width=100%> 
<tr><td colspan=50 class=sitelettitletab> 
<img src=/global/res/images/sin.gif width=0 height=3> 
</td></tr><tr class=sitelettitletab> 

<td><img src=/global/res/images/sin.gif width=3 height=1></td><td class=sitetabnav valign=top><img src=/global/res/themes/corporate/images/tab_left_inactive.gif width=8 height=20></td><td class=sitetabnav valign=middle align=center nowrap><a class=sitetabnav href='javascript:doCommand("doFrontPage")' onmousemove="window.status='Home Page'" onmouseout="window.status=window.defaultStatus" title='Home Page'>Home Page</a></td><td align=right class=sitetabnav valign=top><img src=/global/res/themes/corporate/images/tab_right_inactive.gif width=8 height=20> 
<td><img src=/global/res/images/sin.gif width=3 height=1></td><td class=sitetabnav valign=top><img src=/global/res/themes/corporate/images/tab_left_inactive.gif width=8 height=20></td><td class=sitetabnav valign=middle align=center nowrap><a class=sitetabnav href='javascript:doCommand("doTransmittalsInbox")' onmousemove="window.status='My TCSS'" onmouseout="window.status=window.defaultStatus" title='My TCSS'>My TCSS</a></td><td align=right class=sitetabnav valign=top><img src=/global/res/themes/corporate/images/tab_right_inactive.gif width=8 height=20> 
<td><img src=/global/res/images/sin.gif width=3 height=1></td><td class=siteactivetabnav valign=top><img src=/global/res/themes/corporate/images/tab_left_inactive.gif width=8 height=20></td><td class=siteactivetabnav valign=top><img src=/global/res/images/sin.gif width=5 height=20></td><td class=siteactivetabnav valign=middle align=center nowrap><img src=/global/res/themes/corporate/images/tick.gif width=8 height=9>&nbsp;<a class=siteactivetabnav onmousemove="window.status='Work Under Contract'" onmouseout="window.status=window.defaultStatus">Work Under Contract</a></td><td align=right class=siteactivetabnav valign=top><img src=/global/res/themes/corporate/images/tab_right_inactive.gif width=8 height=20></td> 
<td><img src=/global/res/images/sin.gif width=3 height=1></td><td class=sitetabnav valign=top><img src=/global/res/themes/corporate/images/tab_left_inactive.gif width=8 height=20></td><td class=sitetabnav valign=middle align=center nowrap><a class=sitetabnav href='javascript:doCommand("doGenDocSearch")' onmousemove="window.status='Documents'" onmouseout="window.status=window.defaultStatus" title='Documents'>Documents</a></td><td align=right class=sitetabnav valign=top><img src=/global/res/themes/corporate/images/tab_right_inactive.gif width=8 height=20> 
<td><img src=/global/res/images/sin.gif width=3 height=1></td><td class=sitetabnav valign=top><img src=/global/res/themes/corporate/images/tab_left_inactive.gif width=8 height=20></td><td class=sitetabnav valign=middle align=center nowrap><a class=sitetabnav href='javascript:doCommand("doAssetSearch")' onmousemove="window.status='Reference Library'" onmouseout="window.status=window.defaultStatus" title='Reference Library'>Reference Library</a></td><td align=right class=sitetabnav valign=top><img src=/global/res/themes/corporate/images/tab_right_inactive.gif width=8 height=20> 
<td><img src=/global/res/images/sin.gif width=3 height=1></td><td class=sitetabnav valign=top><img src=/global/res/themes/corporate/images/tab_left_inactive.gif width=8 height=20></td><td class=sitetabnav valign=middle align=center nowrap><a class=sitetabnav href='javascript:doCommand("doAbout")' onmousemove="window.status='Support'" onmouseout="window.status=window.defaultStatus" title='Support'>Support</a></td><td align=right class=sitetabnav valign=top><img src=/global/res/themes/corporate/images/tab_right_inactive.gif width=8 height=20> 
<td><img src=/global/res/images/sin.gif width=3 height=1></td><td class=sitetabnav valign=top><img src=/global/res/themes/corporate/images/tab_left_inactive.gif width=8 height=20></td><td class=sitetabnav valign=middle align=center nowrap><a class=sitetabnav href='javascript:doLogout()' onmousemove="window.status='Close TCSS'" onmouseout="window.status=window.defaultStatus" title='Close TCSS'>Close TCSS</a></td><td align=right class=sitetabnav valign=top><img src=/global/res/themes/corporate/images/tab_right_inactive.gif width=8 height=20> 
<td width=100%><img src=/global/res/images/sin.gif width=1 height=1></td></tr><tr><td colspan=50><img src=/global/res/images/sin.gif width=0 height=2></td></tr></table> 

<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td> 
<img src='/global/res/images/sin.gif' width=1 height=3></td></tr><tr class=sitetabnav><td> 
<table cellpadding=0 cellspacing=0 border=0><tr><script type='text/javascript'> 
TEL_horizontalSubsectionNav('corporate') 
</script><td width=100%>&nbsp;</td></tr></table></td></tr></table> 



<table cellspacing=10 cellpadding=0 border=0 width="100%"> 
<tr><td valign=top width="100%"> 





<TABLE border=0 cellpadding=0 cellspacing=0 width=100%> 
<TR><TD bgcolor=#99ccff> 
<TABLE cellspacing=2 cellpadding=0 border=0 width=100%> 
<TR><TD bgcolor=#F1F8FE> 
<TABLE border=0 cellpadding=0 cellspacing=0> 
<TR><TD colspan=2 height=1 bgcolor=#F1F8FE></TD> 
<TD rowspan=3><IMG border=0 src='images/corner.jpg'></TD> 
</TR><TR><TD><IMG border=0 width=1 height=1 src='images/whitedot.gif'></TD> 
<TD class='groupboxheader'>&nbsp;&nbsp;WUC CSA - Scope Variation - Site & Financial Details &nbsp;&nbsp;</TD></TR></TABLE> 


<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" WIDTH="100%"> 
<TR> 
    <TD CLASS="label" WIDTH="20%">Contract Number:</TD> 
    <TD WIDTH="25%" CLASS="fieldlabel">20003171</TD> 
    <TD CLASS="label" WIDTH="20%">Separable Portion:</TD> 
    <TD WIDTH="25%" CLASS="fieldlabel">30056120</TD> 
</TR> 
<TR> 
    <TD CLASS="label">Work Order:</TD> 
    <TD CLASS="fieldLabel">1</TD> 
    <TD CLASS="label">CSA Number:</TD> 
    <TD CLASS="fieldLabel">4117298</TD> 
</TR> 
<TR> 
    <TD CLASS="label">Current CSA Status:</TD> 
    <TD class="fieldLabel"> 
    Draft</TD> 
    <TD CLASS="label">Initiated By:</TD> 
    <TD CLASS="fieldlabel">CONSTRUCTOR</TD> 
</TR> 
<TR> 
    <TD CLASS="label">Issue Number:</TD> 
    <TD CLASS="fieldlabel">1</TD> 
</TR> 
</TABLE> 

    </TD> 
</TR> 
</TABLE> 
</TD> 
</TR> 
</TABLE> 

<SCRIPT type="text/javascript"> 
function showQuote(sequenceNo) { 
    var f = document.mainForm; 
    switch (parseInt(sequenceNo)) { 
    case 10001: 
     f.command.value = "doCsaViewPSDetails"; 
     break; 
    case 10002: 
     f.command.value = "doCsaViewDRDetails"; 
     break; 
    case 10003: 
     f.command.value = "doCsaViewLSDetails"; 
     break; 
    default: 
     f.sequenceNo.value = sequenceNo; 
     f.command.value = "doCsaViewDIDetails"; 
    } 
    doSubmit(f); 
} 

function showMaterialQuote(sequenceNo) { 
    var f = document.mainForm; 
    f.sequenceNo.value = sequenceNo; 
    f.command.value = "doCsaViewMatDetails"; 
    doSubmit(f); 
} 
//NDCG:For Link to Non Catalogued material screen 
//NDCG:Add:Start 
function showNonCatMaterialQuote(sequenceNo) { 
    var f = document.mainForm; 
    f.command.value = "doCsaViewMatExDetails"; 
    f.sequenceNo.value = sequenceNo; 
    doSubmit(f); 
} 
//NDCG:ADD:End 
</SCRIPT> 

<INPUT type="hidden" name="sequenceNo"> 
<BR> 

<TABLE border="0" cellspacing="1" cellpadding="0" class="table" width="100%"> 
<TR align="middle"> 
    <TD rowspan="2" class=colHeader>Type</TD> 
    <TD colspan="3" class=colHeader>TCSS Calculated</TD> 
    <TD colspan="3" class=colHeader>Quoted</TD> 
    <TD colspan="3" class=colHeader>Approved</TD> 
    <TD rowspan="2" class=colHeader>View</TD> 
</TR> 
<TR align="middle"> 
    <TD class=colHeader>Value</TD> 
    <TD class=colHeader>GST</TD> 
    <TD class=colHeader>Price</TD> 
    <TD class=colHeader>Value</TD> 
    <TD class=colHeader>GST</TD> 
    <TD class=colHeader>Price</TD> 
    <TD class=colHeader>Value</TD> 
    <TD class=colHeader>GST</TD> 
    <TD class=colHeader>Price</TD> 
</TR> 


<TR> 
    <TD class=cell>1. PENRITH - Generic Land & Building - Project</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD class=cell align="center" nowrap> 
    <A HREF="javascript:showQuote('1')"><IMG SRC="/global/res/images/view_white.gif" width=44 height=18 onmousemove="window.status='View Item'" onmouseout="window.status=window.defaultStatus" ALT="View Item" BORDER=0></A> 
    <A HREF="javascript:showMaterialQuote(1)"><IMG SRC=/global/res/images/material.gif width=16 height=16 border=0 onmousemove="window.status='Catalogued Material'" onmouseout="window.status=window.defaultStatus" alt='Catalogued Material'></A> 
    <A HREF="javascript:showNonCatMaterialQuote(1)"><IMG SRC=/global/res/images/material.gif width=16 height=16 border=0 onmousemove="window.status='Non Catalogued Material'" onmouseout="window.status=window.defaultStatus" alt='Non Catalogued Material'></A> 
    </TD> 
</TR> 

<TR> 
    <TD class=cell>Daywork Rates</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD class=cell align="center" nowrap> 
    <A HREF="javascript:showQuote('10002')"><IMG SRC="/global/res/images/view_white.gif" width=44 height=18 onmousemove="window.status='View Item'" onmouseout="window.status=window.defaultStatus" ALT="View Item" BORDER=0></A> 


    </TD> 
</TR> 

<TR> 
    <TD class=cell>Lump Sums</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD nowrap class=rightcell>$0.00</TD> 
    <TD class=cell align="center" nowrap> 
    <A HREF="javascript:showQuote('10003')"><IMG SRC="/global/res/images/view_white.gif" width=44 height=18 onmousemove="window.status='View Item'" onmouseout="window.status=window.defaultStatus" ALT="View Item" BORDER=0></A> 


    </TD> 
</TR> 

Попытки:

driver.find_element_by_css_selector("a[href='javascript:showQuote('10003')']").click() 
driver.find_element_by_xpath("//a[@href="javascript:showQuote('10003')"]").click() 
driver.find_element_by_partial_link_text('showQuote('10003')').click() 
driver.find_element_by_css_selector('[href^=javascript:showQuote('10003')]').click() 
driver.execute_script('showQuote('10003')') 

ответ

0

Вы должны бежать кавычки, чтобы заставить его работать:

driver.find_element_by_css_selector("[href='javascript:showQuote(\\'10003\\')']").click() 

Или с символьной строки:

driver.find_element_by_css_selector(r"[href='javascript:showQuote(\'10003\')']").click() 
1

Вы пытались с помощью XPATH что-то вроде ниже

//tbody/tr[5]/td[11]/a/img 

Я знаю, что позиции позиции tr и td, такие как 5, 11, не подходят, если они продолжают меняться. но попробуйте один раз, чтобы увидеть, может ли он щелкнуть или нет.

Вы можете попробовать, как этот

//a[starts-with(@href, 'javascript:showQuote') and contains(@href, '10003')] 

Если вы используете браузер Firefox, то используйте поджигатель с firepath надстройку, чтобы проверить, если это требуется, забирающий уникальный элемент или нет.

Спасибо, Мурали

+0

не слишком хорошо с пути, в этот пример сложный? любая помощь пожалуйста – Ossama

+0

есть калькулятор онлайн для этого :) – Ossama

Смежные вопросы