ind_element return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"] D:\Users\26226\anaconda3\envs\shixun2\lib\site-packages\selenium\webdriver\remote\webdriver.py:440: in execute self.error_handler.check_response(response) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x000001D25502C9D0> response = {'status': 404, 'value': '{"value":{"error":"no such element","message":"no such element: Unable to locate element: {\...4D4541+740769]\\n\\tBaseThreadInitThunk [0x00007FF8685655A0+16]\\n\\tRtlUserThreadStart [0x00007FF86966485B+43]\\n"}}'} def check_response(self, response: Dict[str, Any]) -> None: """Checks that a JSON response from the WebDriver does not have an error. :Args:
时间: 2024-04-01 18:37:53 浏览: 180
这个错误提示表明在当前页面中无法找到符合指定条件的元素。可能的原因包括:
- 元素定位表达式有误,需要根据实际情况进行调整。
- 页面加载不完整或加载过慢,导致元素还未出现在页面中。可以尝试加入等待逻辑,等待元素出现后再进行操作。
- 页面结构发生变化,导致之前可用的元素定位表达式无法再次使用。需要重新查找可用的元素定位表达式。
您可以先确认一下元素定位表达式是否正确,并尝试加入等待逻辑后再次尝试定位元素。如果仍然无法解决问题,可以尝试重新查找可用的元素定位表达式。
相关问题
class AbstractGreedyAndPrune(): def __init__(self, aoi: AoI, uavs_tours: dict, max_rounds: int, debug: bool = True): self.aoi = aoi self.max_rounds = max_rounds self.debug = debug self.graph = aoi.graph self.nnodes = self.aoi.n_targets self.uavs = list(uavs_tours.keys()) self.nuavs = len(self.uavs) self.uavs_tours = {i: uavs_tours[self.uavs[i]] for i in range(self.nuavs)} self.__check_depots() self.reachable_points = self.__reachable_points() def __pruning(self, mr_solution: MultiRoundSolution) -> MultiRoundSolution: return utility.pruning_multiroundsolution(mr_solution) def solution(self) -> MultiRoundSolution: mrs_builder = MultiRoundSolutionBuilder(self.aoi) for uav in self.uavs: mrs_builder.add_drone(uav) residual_ntours_to_assign = {i : self.max_rounds for i in range(self.nuavs)} tour_to_assign = self.max_rounds * self.nuavs visited_points = set() while not self.greedy_stop_condition(visited_points, tour_to_assign): itd_uav, ind_tour = self.local_optimal_choice(visited_points, residual_ntours_to_assign) residual_ntours_to_assign[itd_uav] -= 1 tour_to_assign -= 1 opt_tour = self.uavs_tours[itd_uav][ind_tour] visited_points |= set(opt_tour.targets_indexes) # update visited points mrs_builder.append_tour(self.uavs[itd_uav], opt_tour) return self.__pruning(mrs_builder.build()) class CumulativeGreedyCoverage(AbstractGreedyAndPrune): choice_dict = {} for ind_uav in range(self.nuavs): uav_residual_rounds = residual_ntours_to_assign[ind_uav] if uav_residual_rounds > 0: uav_tours = self.uavs_tours[ind_uav] for ind_tour in range(len(uav_tours)): tour = uav_tours[ind_tour] quality_tour = self.evaluate_tour(tour, uav_residual_rounds, visited_points) choice_dict[quality_tour] = (ind_uav, ind_tour) best_value = max(choice_dict, key=int) return choice_dict[best_value] def evaluate_tour(self, tour : Tour, round_count : int, visited_points : set): new_points = (set(tour.targets_indexes) - visited_points) return round_count * len(new_points) 如何改写上述程序,使其能返回所有已经探索过的目标点visited_points的数量,请用代码表示
可以在 `solution()` 方法中添加一个变量来记录已经探索过的目标点数量,然后在每次更新 `visited_points` 后更新这个变量。下面是修改后的代码:
```
class AbstractGreedyAndPrune():
def __init__(self, aoi: AoI, uavs_tours: dict, max_rounds: int, debug: bool = True):
self.aoi = aoi
self.max_rounds = max_rounds
self.debug = debug
self.graph = aoi.graph
self.nnodes = self.aoi.n_targets
self.uavs = list(uavs_tours.keys())
self.nuavs = len(self.uavs)
self.uavs_tours = {i: uavs_tours[self.uavs[i]] for i in range(self.nuavs)}
self.__check_depots()
self.reachable_points = self.__reachable_points()
def __pruning(self, mr_solution: MultiRoundSolution) -> MultiRoundSolution:
return utility.pruning_multiroundsolution(mr_solution)
def solution(self) -> Tuple[MultiRoundSolution, int]:
mrs_builder = MultiRoundSolutionBuilder(self.aoi)
for uav in self.uavs:
mrs_builder.add_drone(uav)
residual_ntours_to_assign = {i : self.max_rounds for i in range(self.nuavs)}
tour_to_assign = self.max_rounds * self.nuavs
visited_points = set()
explored_points = 0
while not self.greedy_stop_condition(visited_points, tour_to_assign):
itd_uav, ind_tour = self.local_optimal_choice(visited_points, residual_ntours_to_assign)
residual_ntours_to_assign[itd_uav] -= 1
tour_to_assign -= 1
opt_tour = self.uavs_tours[itd_uav][ind_tour]
new_points = set(opt_tour.targets_indexes) - visited_points
explored_points += len(new_points)
visited_points |= new_points # update visited points
mrs_builder.append_tour(self.uavs[itd_uav], opt_tour)
return self.__pruning(mrs_builder.build()), explored_points
class CumulativeGreedyCoverage(AbstractGreedyAndPrune):
def evaluate_tour(self, tour : Tour, round_count : int, visited_points : set):
new_points = set(tour.targets_indexes) - visited_points
return round_count * len(new_points)
def local_optimal_choice(self, visited_points, residual_ntours_to_assign):
choice_dict = {}
for ind_uav in range(self.nuavs):
uav_residual_rounds = residual_ntours_to_assign[ind_uav]
if uav_residual_rounds > 0:
uav_tours = self.uavs_tours[ind_uav]
for ind_tour in range(len(uav_tours)):
tour = uav_tours[ind_tour]
quality_tour = self.evaluate_tour(tour, uav_residual_rounds, visited_points)
choice_dict[quality_tour] = (ind_uav, ind_tour)
best_value = max(choice_dict, key=int)
return choice_dict[best_value]
def training_step(self, batch, batch_idx, optimizer_idx): # https://github.com/pytorch/pytorch/issues/37142 # try not to fool the heuristics x = self.get_input(batch, self.image_key) xrec, qloss, ind = self(x, return_pred_indices=True) if optimizer_idx == 0: # autoencode aeloss, log_dict_ae = self.loss(qloss, x, xrec, optimizer_idx, self.global_step, last_layer=self.get_last_layer(), split="train", predicted_indices=ind) self.log_dict(log_dict_ae, prog_bar=False, logger=True, on_step=True, on_epoch=True) return aeloss if optimizer_idx == 1: # discriminator discloss, log_dict_disc = self.loss(qloss, x, xrec, optimizer_idx, self.global_step, last_layer=self.get_last_layer(), split="train") self.log_dict(log_dict_disc, prog_bar=False, logger=True, on_step=True, on_epoch=True) return discloss解析
这段代码是PyTorch Lightning中的一个训练步骤函数,用于实现模型的训练过程。该函数接受三个参数:batch、batch_idx和optimizer_idx,分别表示当前训练的批次数据、批次数据的索引和优化器的索引。
在函数内部,首先通过self.get_input(batch, self.image_key)获取输入数据x,并调用self(x, return_pred_indices=True)进行前向传播,得到重构数据xrec、量化损失qloss和预测的编码索引ind。
接下来,根据优化器的索引,分别计算自编码器和判别器的损失函数。如果优化器索引为0,则计算自编码器的损失函数,并调用self.loss函数进行计算。计算完成后,将损失函数的值返回,并使用self.log_dict将损失值记录到日志中。如果优化器索引为1,则计算判别器的损失函数,并调用self.loss函数进行计算。计算完成后,将损失函数的值返回,并使用self.log_dict将损失值记录到日志中。
最终,training_step函数返回损失函数的值,用于在训练过程中更新模型的参数。
阅读全文