Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python在Div内的span内选择一个元素_Python_Selenium - Fatal编程技术网

使用Python在Div内的span内选择一个元素

使用Python在Div内的span内选择一个元素,python,selenium,Python,Selenium,我正在将Selenium测试套件从Java转换为Python。我们的一个助手方法使用以下代码 public String associateCustomSegmentToCampaign(String suffix, int segIndex) { waitForElement("#tab-custom","#tab-custom"); waitForElement("#custom-segments divItemSegments" + segIndex

我正在将Selenium测试套件从Java转换为Python。我们的一个助手方法使用以下代码

public String associateCustomSegmentToCampaign(String suffix, int segIndex)
    {
        waitForElement("#tab-custom","#tab-custom");
        waitForElement("#custom-segments divItemSegments" + segIndex, ".tab--box");

        String segCode = "CustomSeg" + suffix;

        List<FluentWebElement> fluentWebElements = $("li");
        for(FluentWebElement fluentWebElement:fluentWebElements)
        {
            if(fluentWebElement.getId().equalsIgnoreCase("tab-custom"))
            {

                waitForElement("#tab-custom", ".tab--inactive");

                click("#tab-custom");

                click("#custom-segments #divItemSegments" + segIndex + " .fa-plus-circle");
                //fill("#txtSegCode" + segCodeIndex).with(segCode);
            }
        }

        return segCode;
    }
变成巨蟒


任何帮助

字符串都是css选择器。在python中,它将如下所示:

driver.find_element_by_css_selector("#custom-segments #divItemSegments" + segIndex + " .fa-plus-circle").click()

什么是点击?你能分享同样的代码吗?它是一个函数,它接受字符串参数,识别与之对应的元素并单击它。是的,我理解,你能分享单击方法的代码吗?到目前为止你都尝试了什么?你的问题不清楚你想解决什么问题。click()方法是否因异常而失败?或者您只是在构造要传递到方法中的字符串时遇到困难?click()是fluent selenium的内置函数。我的问题完全不同。谢谢你的帮助
driver.find_element_by_css_selector("#custom-segments #divItemSegments" + segIndex + " .fa-plus-circle").click()