下面是代码:
def _get_unique_code(self):
"""
To be used only once in the save method. It creates the unique code.
"""
import random
self.code = f"{self.publication.pub_id}-{self.language.upper()}-{self.format.upper()}-{random.randint(1,10001)}"
while Document.objects.filter(code=self.code).exists():
self.code = f"{self.publication.pub_id}-{self.language.upper()}-{self.format.upper()}-{random.randint(1,10001)}"
return self.code
def save(self, *args, **kwargs):
if not self.code:
self.code = self._get_unique_code()
super(Document, self).save()
我在硒中尝试了以下代码:
<div class="footer-bottom-left">
<div class="campaignUser">Campaign User</div>
<div class="callLogLookUp">Call Log Look Up</div>
</div>
答案 0 :(得分:1)
您错过了班级名称中的破折号。另外,您需要删除第二个点(也不需要第一个)。因此,而不是
.//div[@class='footer-bottomleft'].//div[@class='callLogLookUp']
尝试
//div[@class='footer-bottom-left']//div[@class='callLogLookUp']
您可能还需要实现ExplicitWait:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='footer-bottom-left']//div[@class='callLogLookUp']"))).click();