2016-11-08 5 views
0

Hallo alle Ich benutze Python 3.0 und ich versuche, klicken Sie auf einen Link in einer Tabelle.kann nicht Link in Tabelle mit Python3 mit Selen

Bei Strom kann ich den Link nicht finden, also kann ich nicht darauf klicken.

Unten ist die html des ausgewählten Elements

Apologies hier ist ein besseres Beispiel für den Code ...

<div id="divMyActivities2" originalheight="125px" style="overflow-y:auto;top:0px;left:0px;width:451px;height:125px;"> 
     <table id="tblMyActivities" class="podborder" border="0" cellpadding="3" cellspacing="0" style="overflow-y: auto; table-layout: fixed; border: 1px solid #CCCCCC; border-top: none; width: 100%; border-top-left-radius: 0px; border-top-right-radius: 0px"> 
<tr> 
    <td class="customheader" style="border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; width: 100%; color: #004a78; background: #e6ebf1 !important; font-size: 11px;" align="left">&nbsp;&nbsp;<b>Type of Activity</b> 
       </td> 
    <td class="customheader" style="border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; width: 50px; color: #004a78; background: #e6ebf1 !important; font-size: 11px;" align="center"><b>Past Due</b> 
       </td> 
    <td class="customheader" style="border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; width: 60px; color: #004a78; background: #e6ebf1 !important; font-size: 11px;" align="center"><b>This Week</b> 
       </td> 
    <td class="customheader" style="border-bottom: 1px solid #CCCCCC; font-size: 11px; width: 50px; color: #004a78; background: #e6ebf1 !important;" align="center"><b>All</b> 
       </td> 
</tr> 
<tr class="blacktext"> 
    <td style="border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; text-align: left; width: 100%;">&nbsp; 
        <img src="../../common/images/cwtoday_bullet.gif" border="0" /> 
        <label onclick="pageNav('crmSales');" class="tablelink">CRM/Sales Activities</label> 
       </td> 
    <td id="tdSalesPastDue" class="tabletext" style="border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; width: 50px;" align="center">&nbsp;</td> 
    <td id="tdSalesThisWeek" class="tabletext" style="border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; width: 60px;" align="center">&nbsp;</td> 
    <td id="tdSalesAll" class="tabletext" style="border-bottom: 1px solid #CCCCCC; width: 50px;" align="center">&nbsp; 
       </td> 
</tr> 
<tr id="trProjAct" class="blacktext"> 
    <td style="border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; text-align: left; width: 100%; background: #f6f6f6;">&nbsp 
        <img src="../../common/images/cwtoday_bullet.gif" border="0" /> 
        <label onclick="pageNav('projectActs');" class="tablelink">Project Tickets</label> 
       </td> 
    <td id="tdPrjActPastDue" class="tabletext" style="border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; width: 50px; background: #f6f6f6;" align="center">&nbsp;</td> 
    <td id="tdPrjActThisWeek" class="tabletext" style="border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; width: 60px; background: #f6f6f6;" align="center">&nbsp;</td> 
    <td id="tdPrjActAll" class="tabletext" style="border-bottom: 1px solid #CCCCCC; width: 50px; background: #f6f6f6;" align="center">&nbsp;</td> 
</tr> 
<tr class="blacktext"> 
    <td style="border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; text-align: left; width: 100%;">&nbsp; 
        <img src="../../common/images/cwtoday_bullet.gif" border="0" /> 
        <label onclick="pageNav('projectIssues');" class="tablelink">Project Issues</label> 
       </td> 
    <td id="tdPrjIssPastDue" class="tabletext" style="border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; width: 50px;" align="center">&nbsp;</td> 
    <td id="tdPrjIssThisWeek" class="tabletext" style="border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; width: 60px;" align="center">&nbsp;</td> 
    <td id="tdPrjIssAll" class="tabletext" style="border-bottom: 1px solid #CCCCCC; width: 50px;" align="center">&nbsp;</td> 
</tr> 
<tr class="blacktext"> 
    <td style="border-right: 1px solid #CCCCCC; border-bottom-left-radius: 6px; text-align: left; width: 100%; background: #f6f6f6;">&nbsp; 
        <img src="../../common/images/cwtoday_bullet.gif" border="0" /> 
        <label onclick="pageNav('serviceRequests');" class="tablelink">Service Tickets</label> 
       </td> 
    <td id="tdSRPastDue" class="tabletext" style="border-right: 1px solid #CCCCCC; width: 50px; background: #f6f6f6;" align="center">&nbsp;</td> 
    <td id="tdSRThisWeek" class="tabletext" style="border-right: 1px solid #CCCCCC; width: 60px; background: #f6f6f6;" align="center">&nbsp;</td> 
    <td id="tdSRAll" class="tabletext" align="center" style="width: 50px; background: #f6f6f6; border-bottom-right-radius: 6px;">&nbsp;</td> 
</tr> 

ich dieses Element wählen versuche:

<label onclick="pageNav('serviceRequests');" class="tablelink">Service Tickets</label> 

Was ich versucht habe ....

Versuchte:

driver.find_element_by_partial_link_text('Tickets').click() 

Ausnahme:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"partial link text","selector":"Tickets" 

Versuchte:

driver.find_element_by_link_text('Service Tickets').click() 

Ausnahme:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"Service Tickets" 

Versuchte

driver.find_elements_by_css_selector(".tablelink") 

Ergebnis:

produces an empty list "[]" 

Versuchte:

driver.find_element_by_tag_name("label") 

Ausnahme:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"tag name","selector":"label"} 

fand ich diese URL, aber ich konnte den Code nicht ändern: Find and click an item from 'onclick' partial value

  • wild guess ich müde von der Verbindung zu dekodieren

Versucht:

driver.find_element_by_css_selector("tablelink[onclick*='Service Tickets']") 

Ausnahme:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"tablelink[onclick*='Service Tickets']"} 

Jede Hilfe wäre toll, danke im voraus.

+1

Sie können Ihren HTML-Teil bereitstellen, damit wir verstehen, was eigentlich sein sollte. Ihr Code und HTML scheinen nicht übereinzustimmen. –

+0

Überprüfen Sie, ob das Element in einem Iframe ist. Stellen Sie sicher, dass Sie bei Bedarf auf das Element warten, und versuchen Sie es mit einem CSS-Selektor wie: "label [onclick * = serviceRequests]" – lauda

Antwort

0

Apolgoes lernen immer noch alles.

Ich musste Iframe dann ich war in der Lage, den Code von XPATH zu lokalisieren.

Ich wollte nicht den gesamten Code auf einmal einfügen, da Seiten lange durchforsten.

driver.switch_to_frame(driver.find_element_by_class_name("gwt-Frame")) 
driver.find_element_by_xpath("//label[contains(.,'Service Tickets')]").click() 

Danke für Ihre Zeit.