Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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
如何使用selenium从li中计数和获取文本_Selenium - Fatal编程技术网

如何使用selenium从li中计数和获取文本

如何使用selenium从li中计数和获取文本,selenium,Selenium,下面是我的DOM <div class="demo-frame"> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <style> #feedback { font-size: 1.4em; } #selectable .ui-selecting { background: #FECA40; } #selectable .ui-se

下面是我的DOM

<div class="demo-frame">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <style>
#feedback { font-size: 1.4em; }
#selectable .ui-selecting { background: #FECA40; }
#selectable .ui-selected { background: #F39814; color: white; }
#selectable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
#selectable li { margin: 3px; padding: 0.4em; font-size: 1.4em; height:  56px; }

</style>
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script>
$( function() {
    $( "#selectable" ).selectable();
} );
</script>
    <ol id="selectable" class="ui-selectable">
        <li class="ui-widget-content ui-selectee">Item 1</li>
        <li class="ui-widget-content ui-selectee">Item 2</li>
        <li class="ui-widget-content ui-selectee">Item 3</li>
        <li class="ui-widget-content ui-selectee">Item 4</li>
        <li class="ui-widget-content ui-selectee">Item 5</li>
        <li class="ui-widget-content ui-selectee">Item 6</li>
        <li class="ui-widget-content ui-selectee">Item 7</li>
    </ol>
</div>
我需要单击每个项目并按顺序打印项目名称,为此,我尝试获取li标记的计数,然后使用for循环进行迭代

List<WebElement> countryUL = driver.findElements(By.xpath("//*[@class='demo-frame']/ol"));

System.out.println(countryUL.size());
但是上面的打印1我不知道我犯了什么错误

您应该使用

List<WebElement> countryUL = driver.findElements(By.xpath("//div[@class='demo-frame']/ol/li"));
你应该使用

List<WebElement> countryUL = driver.findElements(By.xpath("//div[@class='demo-frame']/ol/li"));

你能详细地帮我吗?这是我正在尝试自动化的,我需要点击每一个项目并获得它的文本。你能帮我详细了解一下吗?这是我试图自动化的,我需要点击每一个项目,并获得的文本it@AmitJain:driver.findElementBy.tagNameol;返回未列出的webelement。@KunduK-已更新,有些内容已丢失。。书面循环,因为他要求打印所有项目。@AmitJain:driver.findElementBy.tagNameol;返回未列出的webelement。@KunduK-已更新,有些内容已丢失。。书面循环,因为他要求打印所有项目。。