2016-10-05 68 views
1

我正在尝试改进我的Selenium技能,对于此任务,我尝试单击按表格元素名称选择它的方式。Selenium,Python,无法通过检查表单项来点击按钮项目名称

例如,在这种情况下,我想查找EB Trial 2,然后单击与此相关的按钮import

<tr ng-repeat="event in bcEvents" class="ng-scope"> 
      <td> 
       <div class="dib fxac"> 
        <i class="icon-event fs32 text-light-blue mr15"></i> 
        <div class="event-inner"> 
         <a href="" class="link link-underline db ng-binding">EB Trial2</a> 
         <span class="db fs-small text-light-blue ng-binding">11/15/2016</span> 
        </div> 
       </div> 
      </td> 
      <td ng-switch="bc_source"> 
       <!-- ngSwitchWhen: 2 --><div ng-switch-when="2" class="ng-scope"> 
        <a href="" ng-click="import_bc_event(event)" class="btn btn-icon btn-orange"> 
         <i class="icon icon-eventbrite-icon"></i> Import 
        </a> 
       </div> 
       <!-- ngSwitchWhen: 8 --> 
       <!-- ngSwitchWhen: A --> 
       <!-- ngSwitchWhen: 9 --> 
       <!-- ngSwitchWhen: B --> 
      </td> 

      <!-- ngIf: bc_source != 2 --> 
     </tr> 

我尝试XPath去实现它,但它没有工作

driver.find_element_by_xpath("//td[contains(text(),'EB Trial2')]/preceding-sibling::td[1]").click() 

我无法理解了它是如何做到这一点

任何人可以帮助我这个?

+0

请发表您使用什么错误,你所遇到的代码等。 – JeffC

+0

我尝试通过XPath访问它,但它没有工作driver.find_element_by_xpath(“// td [contains(text(),'EB Trial2')]/preceding-sibling :: td [1]”)。click ) 喜欢这个。我无法弄清楚如何去做。 – ogul

回答

0

I want to locate EB Trial 2 then click the import button which is related to that

你应该尝试使用xpath为:

driver.find_element_by_xpath(".//td[descendant::a[text()='EB Trial2']]/following-sibling::td//a[normalize-space(.)='Import']").click() 
+1

这很好用!非常感谢 – ogul

+0

顺便说一句,我试图等待,直到按钮可点击这个代码元素= WebDriverWait(驱动程序,60).until( EC.element_to_be_clickable((By.XPATH,“”)),但它给了我一个未知的错误:Element在很多时候点不可点击 – ogul