如何在Tester-> click in codeception中忽略html?

时间:2019-05-15 10:37:36

标签: codeception

我有一个看起来像这样的html字符串:

<div>firstname <br> <span>lastname</span></div>

是否可以在我的测试仪上运行:

$I->click('firstname lastname');

忽略标签吗?

1 个答案:

答案 0 :(得分:1)

您可以像这样使用xpath

def loadImage(self):
    # load image
    imagepath = self.imageList[self.cur - 1]
    self.img = Image.open(imagepath)
    self.tkimg = ImageTk.PhotoImage(self.img)
    self.mainPanel.config(width = max(self.tkimg.width(), 400), height = max(self.tkimg.height(), 400))
    self.mainPanel.create_image(0, 0, image = self.tkimg, anchor=NW)
    self.progLabel.config(text = "%04d/%04d" %(self.cur, self.total))

    # load labels
    self.clearBBox()
    self.imagename = os.path.split(imagepath)[-1].split('.')[0]
    labelname = self.imagename + '.txt'
    self.labelfilename = os.path.join(self.outDir, labelname)
    bbox_cnt = 0
    if os.path.exists(self.labelfilename):
        with open(self.labelfilename) as f:
            for (i, line) in enumerate(f):
                if i == 0:
                    bbox_cnt = int(line.strip())
                    continue
                tmp = [int(t.strip()) for t in line.split()]

                self.bboxList.append(tuple(tmp))
                tmpId = self.mainPanel.create_rectangle(tmp[0], tmp[1], \
                                                        tmp[2], tmp[3], \
                                                        width = 2, \
                                                        outline = COLORS[(len(self.bboxList)-1) % len(COLORS)])
                self.bboxIdList.append(tmpId)
                self.listbox.insert(END, '(%d, %d) -> (%d, %d)' %(tmp[0], tmp[1], tmp[2], tmp[3]))
                self.listbox.itemconfig(len(self.bboxIdList) - 1, fg = COLORS[(len(self.bboxIdList) - 1) % len(COLORS)])


def saveImage(self):
    with open(self.labelfilename, 'w') as f:
        f.write('%d\nz' %len(self.bboxList))
        for bbox in self.bboxList:
            f.write(' '.join(map(str, bbox)) + '\n')
    print 'Image No. %d saved' %(self.cur)