小编Jea*_*ger的帖子

检查元素在 Playwright 中是否可见

我正在使用 Playwright 1.15.2 进行测试并面临元素可见性的问题。我想检查模式在屏幕上是否可见,以便我可以将其关闭。情态动词以display:none开头并变为display:block。此外,模式会通知表单数据不正确,因此它可能会出现,也可能不会出现(即我不能waitForSelector)。

目前,我有类似以下的代码:

const myModal = await page.$("#modal");
if (await myModal.isVisible()) {
  await page.waitForSelector('#modal > .modal-dialog > .modal-content > .modal-footer > .btn-close');
  await page.click('#modal > .modal-dialog > .modal-content > .modal-footer > .btn-close');
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

const myModal = await page.$("#modal:visible");
if (myModal) {
...
Run Code Online (Sandbox Code Playgroud)

使用page.$("text=modal title >> visible=true")或切换page.$page.locator(使用所有上述选择器)也不起作用。

这个问题的公认答案效果不佳。

有人能帮我吗?

javascript playwright

17
推荐指数
1
解决办法
7万
查看次数

javascript替换n元树对象中的属性名称

假设我有一个像这样的 n 元树结构(以 json 形式):

[
  {
    "text": "Some title",
    "children": [
      {
        "text": "Some title",
        "children": [
          ...
        ]
      },
      ...  
    ]
  }
]
Run Code Online (Sandbox Code Playgroud)

我既不知道节点将有多少个子节点,也不知道树的深度。

我想做的是将所有孩子的财产名称更改text为。name

我已经尝试过这个,使用递归函数func

func(tree) {
  if (!tree) return;

  for (let node of tree) {
    node.name = node.text
    delete node.text;
    
    return func(node.children);
  }
}
Run Code Online (Sandbox Code Playgroud)

但这没有用。我该怎么做呢?

javascript

5
推荐指数
1
解决办法
713
查看次数

为什么 Spring Security 身份验证会导致 CORS 错误

我有一个用 Java 制作的带有 Spring Boot、Security 和 Web 的后端服务器和一个用 Angular 制作的客户端。

目前我正在尝试在localhost:8080/resource.

该地址的控制器如下所示:

@RestController
public class IndexController {
    @CrossOrigin
    @RequestMapping("/resource")
    public Map<String, Object> home() {
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("id", UUID.randomUUID().toString());
        model.put("content", "Hello World");

        return model;
    }
}
Run Code Online (Sandbox Code Playgroud)

Angular 客户端(执行请求的部分)是这样的:

import { Component } from "@angular/core";
import { HttpClient } from "@angular/common/http";

@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.css"]
})
export class AppComponent {
    public title = "Security Client";
    public greeting = {};

    constructor(private http: HttpClient) …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security cors

1
推荐指数
1
解决办法
1132
查看次数

标签 统计

javascript ×2

cors ×1

java ×1

playwright ×1

spring ×1

spring-security ×1