添加到页面的动态按钮,不知道如何找到该元素

时间:2016-07-12 13:22:02

标签: selenium selenium-webdriver automation

我有一个页面的计算结构,我不知道如何找到元素......

该页面包含由用户创建的文件夹,我需要创建一个文件夹然后单击它,但我不知道如何找到我创建的元素。结构看起来像这样:

/usr/lib/sagemath/local/lib/python2.7/site-packages/matplotlib-1.5.1-py2.7-linux-x86_64.egg/matplotlib/text.py in set_text(self, s)
   1204         ACCEPTS: string or anything printable with '%s' conversion.
   1205         """
-> 1206         self._text = '%s' % (s,)
   1207         self.stale = True
   1208 

UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)

class =“grid-row-element-name”包含创建的文件夹的名称(每个文件夹都有自己的名称)....

我不知道如何继续测试,因为我无法点击文件夹....

谢谢。

2 个答案:

答案 0 :(得分:0)

由于您正在寻找具有您创建的特定文本的元素(文件夹名称),我将通过查找包含文件夹名称的A标记来实现此目的。

顺便说一句,你没有用语言标记你的问题所以下面是Java。如果需要,您应该可以通过重用XPath轻松地将其转换为另一种语言。

String folderName = "Eclipse111";
// create folder
WebElement folder = driver.findElement(By.xpath("//a[text()='" + folderName + "']"));

答案 1 :(得分:0)

尝试以下方法,因为你说过" grid-row-element-name"有文件夹名称然后尝试在cssSelector中使用该类名。

List<WebElement> elements = driver.findElements(By.cssSelector("a.grid-row-element-name"));
        String folderName = null; //name of the folder which you want to click.

        for (WebElement ele : elements) { //Iterate over the loop 
            if (ele.getText().equalsIgnoreCase(folderName)) {
                ele.click();//once the folder you want is found go for the click.
            }
        }
        //OR
        //To click on the last element try this
        elements.get(elements.size()-1).click();
相关问题