gpt4 book ai didi

webdriver - Selenium WebDriver 如何克服同源策略

转载 作者:行者123 更新时间:2023-12-03 15:30:19 28 4
gpt4 key购买 nike

Selenium WebDriver 如何克服同源策略?

Selenium RC 中存在同源策略问题

最佳答案

First of all “Same Origin Policy” is introduced for security reason, and it ensures that content of your site will never be accessible by a script from another site. As per the policy, any code loaded within the browser can only operate within that website’s domain.



-------------------------------------------------- ------------------------------------------- -------- ---------------------------它做了什么???

Same Origin policy prohibits JavaScript code from accessing elements from a domain that is different from where it was launched. Example, the HTML code in www.google.com uses a JavaScript program "testScript.js". The same origin policy will only allow testScript.js to access pages within google.com such as google.com/mail, google.com/login, or google.com/signup. However, it cannot access pages from different sites such as yahoo.com/search or fbk.com because they belong to different domains.



这就是为什么在 Selenium RC 之前,测试人员需要安装 Selenium Core(一个 JavaScript 程序)和包含正在测试的 Web 应用程序的 Web 服务器的本地副本,以便它们属于同一个域。 -------------------------------------------------- -------------------------------------------------- -------------------------------- 它是如何避免的???

To avoid “Same Origin Policy” proxy injection method is used, in proxy injection mode the Selenium Server acts as a client configured HTTP proxy , which sits between the browser and application under test and then masks the AUT under a fictional URL



Selenium 使用 java 脚本在浏览器上驱动测试; Selenium 将自己的 js 注入(inject)到从 aut 返回的响应中。但是有一个java脚本安全限制 (同源政策)只有当 js 也来自与 html 相同的域时,它才允许您使用 js 修改页面的 html。这种安全限制非常重要,但会破坏 Selenium 的工作。这就是 Selenium 服务器发挥重要作用的地方。

关于webdriver - Selenium WebDriver 如何克服同源策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32858214/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com