【问题标题】:How to clik on a text in the div如何单击 div 中的文本
【发布时间】:2012-04-01 06:00:29
【问题描述】:

谁能帮我在一个div下选择文本(en_GW)?

<-div class="x-combo-list-inner" id="cq-gen339" style="width: 253px; height: 300px;">
<-div class="x-combo-list-item  x-combo-selected" ext:qtip="">en_GW<-/div><-div>

注意:下面的代码不起作用:

driver.findElement(By.className("x-combo-list-item  x-combo-selected")).click();

错误

不支持复合类名。考虑搜索一个类名并过滤结果。

【问题讨论】:

    标签: java selenium webdriver selenium-webdriver


    【解决方案1】:
    // xpath
    driver.findElement(By.xpath("//div[contains(@class, 'x-combo-list-item x-combo-selected')]")).click(); 
    
    // css selector
    driver.findElement(By.cssSelector("div.x-combo-list-item.x-combo-selected")).click(); 
    

    【讨论】:

      【解决方案2】:
        $.fn.clickToggle = function(func1, func2) {
        var funcs = [func1, func2];
        this.data('toggleclicked', 0);
        this.click(function() {
            var data = $(this).data();
            var tc = data.toggleclicked;
            $.proxy(funcs[tc], this)();
            data.toggleclicked = (tc + 1) % 2;
        });
        return this;
         };
      
          $(txt5).clickToggle(function() {
      alert('First handler: ' + $(this).text());
      }, function() {
      alert('Second handler: ' + $(this).text());
      
      });
      

      如果点击 div 计数会增加,我没有元素。同时点击其他 div 首先将计数为 0 ?

      【讨论】:

        猜你喜欢
        • 2017-11-28
        • 2013-02-02
        • 1970-01-01
        • 1970-01-01
        • 2015-10-19
        • 1970-01-01
        • 1970-01-01
        • 2016-05-12
        • 2011-02-05
        相关资源
        最近更新 更多