mardi 24 juillet 2018

Check If element exists in python selenium

Following is my python selenium code

def provideDetails(self, titleEleName, titleText, sbmtBtnName, dropdownOptn, dropdownName):

        self.ui.jobs.setJobTitleEleName(titleEleName, titleText)

        elem = self.ui.jobs.selectButton(dropdownName)

        if elem.is_displayed():
            self.ui.jobs.selectButton(dropdownName)
            self.ui.sleep(4)
            self.ui.jobs.selectAor(dropdownOptn)
        else:
            self.ui.jobs.selectAddAors(dropdownOptn)
            self.ui.sleep(4)

        self.ui.jobs.selectButton(sbmtBtnName)

I have to check, if the 'elem' is present or not. And if it is present, 'if' condition should happen, and if not, 'else' condition should work. I tried this code. And I got this error "Attribute error: None Type object has no attribute 'is_displayed'. Any help would be appreciated. Thanks.

Aucun commentaire:

Enregistrer un commentaire