使用Selenium Web驱动程序单击Python中未发生的事件

时间:2018-05-05 11:32:06

标签: python selenium selenium-webdriver

朋友们在使用Python和Selenium网络驱动程序的情况下再次面临挑战: -

  1. 单击链接名称“区域排名Web”时未发生单击事件。 MSTR报告的HTML代码如下: -

    <td class="mstrLargeIconViewItemText" rowspan="1" colspan="1" cx="[2,1,0,5,1,6,7]" cxid="folderAllModes_cmm" oid="600E4BA841AC84797221F7BB5262C3E0" oty="55"><a title="Run Document" class="mstrLargeIconViewItemLink" onclick="return submitLink(this, event);" href="Main.aspx?evt=2048001&amp;src=Main.aspx.2048001&amp;visMode=0&amp;currentViewMedia=1&amp;documentID=600E4BA841AC84797221F7BB5262C3E0" runasexpress="1" alt="Run Document"></a><div class="mstrLargeIconViewItemName"><span sty="nm"><a title="Area Rank Web" class="mstrLink" onclick="return submitLink(this, event);" href="Main.aspx?evt=2048001&amp;src=Main.aspx.2048001&amp;visMode=0&amp;currentViewMedia=1&amp;documentID=600E4BA841AC84797221F7BB5262C3E0" runasexpress="1">Area Rank Web</a></span></div><div class="mstrLargeIconViewItemOwner"><label>Owner:</label><span><div title="Administrator" class="owner">Administrator</div></span></div><div class="mstrLargeIconViewItemModified"><label>Modified:</label><span><div timestamp="1525148536000">5/1/18 4:22:16 AM</div></span></div><div class="mstrLargeIconViewItemDescription"></div><div></div><div class="mstrLargeIconViewItemActions"><span><a class="mstrLink" onclick="if (!mstrFolderActions.checkACL(this, event, '600E4BA841AC84797221F7BB5262C3E0', 55)) return; return submitLink(this, event);" href="Main.aspx?evt=3032&amp;src=Main.aspx.3032&amp;objectType_3032=55&amp;objectID_3032=600E4BA841AC84797221F7BB5262C3E0" ty="sub">Subscriptions</a></span></div></td>
    

    我尝试了以下方法,但没有取得成功:

    #driver.find_element_by_xpath(".//*[title='Area Rank Web']").click();
    #driver.find_elements_by_class_name (("mstrLargeIconViewItemName") and contains(.,'Area Rank Web')).click()
    #driver.find_element_by_id("600E4BA841AC84797221F7BB5262C3E0").click()
    #driver.find_element_by_css_selector("600E4BA841AC84797221F7BB5262C3E0").click()
    #WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='mstrLargeIconViewItemText']/span[@class='mstrIcon-lg' and contains(.,'Area Rank Web')]"))).click()
    

    2。 有一个块有两个值: - AREA,DISTRICT。您可以选择多个值,然后单击箭头按钮,将所选内容移动到块的右侧,然后单击提交按钮

    HTML code:

    <div title="AREA" class="mstrListBlockItemSelected" style="margin-top: 0px;"><div class="mstrBGIcon_ae mstrListBlockItemName" style="background-position: 2px 50%; padding-left: 23px;">DSI</div></div>
    
    <div title="DISTRICT" class="mstrListBlockItem" style="margin-top: 0px;"><div class="mstrBGIcon_ae mstrListBlockItemName" style="background-position: 2px 50%; padding-left: 23px;">ONC</div></div>
    
  2. 尝试以下方式但未发生点击事件

1 个答案:

答案 0 :(得分:0)

您可以尝试使用link_text / partial_link_text吗?

driver.find_element_by_link_text('Area Rank Web').click()

OR

driver.find_element_by_partial_link_text('Area Rank Web').click()

此外,请在点击链接之前尝试明确等待。

WebDriverWait(self.driver, 10).until(expected_conditions.element_to_be_clickable(
             (By.LINK_TEXT, 'Area Rank Web')
))

如果上述所有操作都失败,请使用execute_script方法调用链接上的点击事件

link = driver.find_element_by_link_text('Area Rank Web')
driver.execute_script('arguments[0].click();', link)