我有一個應用程序,用戶可以點擊按鈕並彈出窗口顯示。然後,在此彈出窗口中單擊提交按鈕後,窗口將關閉,用戶繼續在主窗口中工作。Selenium:彈出窗口關閉後用戶切換到主窗口
我希望能夠在主窗口中使用硒選擇元素,然後在彈出窗口中選擇元素,彈出窗口關閉後再次在主窗口中選擇元素。任何想法我會如何做到這一點?
編輯:
這是我的代碼。我正在使用django-addanother創建彈出窗體。主要形式是Robject形式。休息表單是彈出窗口。
class CreateRobjectView(PermissionRequiredMixin, CreateView):
template_name = 'robjects/create_robject.html'
success_url = "/projects/proj_1/robjects/"
raise_exception = True
permission_required = ['projects.can_visit_project',
'projects.can_modify_project']
def get(self, request, *args, **kwargs):
Name.objects.filter(robjects=None).delete()
RobjectFile.objects.filter(robjects=None).delete()
return super().get(request, *args, **kwargs)
def form_valid(self, form):
form.save()
robject = Robject.objects.last()
Name.objects.filter(robjects=None).delete()
RobjectFile.objects.filter(robjects=None).delete()
return redirect("robjects_list", self.args[0])
def get_initial(self):
return {
"create_by": self.request.user,
"project": Project.objects.get(name=self.args[0])
}
def get_form_class(self):
form = modelform_factory(Robject, form=ModelForm, exclude=["modify_by"],
widgets={
'names': AddAnotherWidgetWrapper(
forms.SelectMultiple,
reverse_lazy('add_name', args=[self.args[0]]),
),
'files': AddAnotherWidgetWrapper(
forms.SelectMultiple,
reverse_lazy('add_file', args=[self.args[0]]),
),
'tags': AddAnotherWidgetWrapper(
forms.SelectMultiple,
reverse_lazy('add_tag', args=[self.args[0]]),
),
'project': forms.HiddenInput(),
'create_by': forms.HiddenInput()
})
return form
def get_permission_object(self):
project = Project.objects.get(name=self.args[0])
return project
class CreateNameView(LoginRequiredMixin, CreatePopupMixin, CreateView):
model = Name
fields = "__all__"
template_name = 'robjects/create_name.html'
def get_initial(self):
return {"project": Project.objects.get(name=self.args[0])}
def get_form(self):
form = super(CreateNameView, self).get_form()
form.fields['project'].widget = forms.HiddenInput()
return form
class RobjectFileCreateView(LoginRequiredMixin, CreatePopupMixin, CreateView):
model = RobjectFile
fields = ['_file', 'description']
template_name = 'robjects/create_robject_file.html'
class TagCreateView(LoginRequiredMixin, CreatePopupMixin, CreateView):
model = Tag
fields = ['name', "project"]
template_name = 'robjects/create_tag.html'
def get_initial(self):
return {"project": Project.objects.get(name=self.args[0])}
def get_form(self):
form = super(TagCreateView, self).get_form()
form.fields['project'].widget = forms.HiddenInput()
return form
在此先感謝。
向我們顯示您的代碼, – Kapil