2016-11-08 29 views
0

大家好,我正在使用Python 3.0,我试图点击表中的链接。无法找到使用python3与硒的链接

目前我找不到链接,所以我不能点击它。

下面是所选元素

道歉这里是代码的一个更好的例子的HTML ...

<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> 

我想选择这个元素:

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

我试过....

尝试:

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

例外:

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

尝试:

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

例外:

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

试过

driver.find_elements_by_css_selector(".tablelink") 

结果:

produces an empty list "[]" 

尝试:

driver.find_element_by_tag_name("label") 

例外:

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

我发现这个网址,但我无法改变的代码:Find and click an item from 'onclick' partial value

  • 胡乱猜测我累了,从链接

解码试过:

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

例外:

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

任何帮助将是巨大的,在此先感谢。

+1

您可能会提供您的HTML部分,以便我们能够理解实际应该是什么。您的代码和HTML似乎不匹配。 –

+0

检查元素是否在iframe中。确保你需要等待元素,并尝试使用一个CSS选择器,如:“label [onclick * = serviceRequests]” – lauda

回答

0

Apolgoes仍在学习这一切。

我不得不切换iframe,然后我可以通过XPATH找到代码。

我不想一次粘贴整个代码,因为它只是需要长时间浏览。

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

谢谢你的时间。