ruby selenium点击带有班级名称的按钮

时间:2014-09-12 08:55:36

标签: ruby selenium-webdriver

我使用ruby和selenium来测试网页,下面有两个按钮

<div class="AVdis">
  <span class="gwt-InlineHTML"/>
    <a class="AVcur" name="attendEdit"; font-size: 12px;">[edit]</a>
</div>
<div class="lineHeight">
  <button type="button" class="pcbtn" style="display: inline-block;">yes</button>
</div>

我试图使用

driver.find_elements(:class, 'AVcur').click 
driver.find_elements(:class, 'pcbtn').click 

但它不起作用,请告知。

由于

更新了完整的HTML代码(类的部分代码&#39; pcbtn&#39;只是,它不包含带有类&#39; AVcur&#39;的部分。):

<body>
  <iframe src="javascript:'';" id="__gwt_historyFrame" style="width: 0px; height: 0px; border: 0px; display: block;"/>
  <iframe src="javascript:''" id="Attend" tabindex="-1" style="position: absolute; width: 0px; height: 0px; border: none;"/>
  <div style="display: none;"/>
    <div class="GFKFO5SBPF hBody nClientFalse">
      <div class="left" style="width: 198px;">
        <div class="contents nClientFalse2">
          <div class="AVright">
            <div class="GFKFO5SBIQ">
              <div class="AVfirstTd">
                <table cellspacing="0" cellpadding="0">
                  <tbody>
                    <tr>
                      <td align="left" style="vertical-align: top;">
                        <div>
                          <table cellpadding="0" cellspacing="0" class="pcattd_record" width="630px">
                            <tbody>
                              <tr class="GFKFO5SBCS">
                                <tr class="GFKFO5SBCS">
                                  <th>
                                    <td>
                                      <table class="noborder">
                                        <tbody>
                                          <tr>
                                            <td>
                                            <td>
                                              <div class="lineHeight">
                                                <button type="button" class="pcbtn" style="display: inline-block;">press button</button>

2 个答案:

答案 0 :(得分:0)

尝试使用xpath:

单击它
driver.find_element(:xpath, "//div[@class='AVdis']//a[@name='attendEdit']").click

第二个元素xpath:

driver.find_element(:xpath, "//div[@class='lineHeight']//button[@class='pcbtn'][text()='yes']").click

答案 1 :(得分:0)

点击元素:

driver.find_element(css: 'a').click
相关问题