1

I don't know why but i encounter this issue in only payment part. I execute script with other pages but i didn't get this warning.

def payments(self, cvc):
    print("Paying for the shoe.")
    self.chrome.execute_script("scroll(0, 300)") # for seeing buttons
    # Need class and name at the same time because it is inside in iframe
    self.wait_until_visible(xpath="//input[@class='pre-search-input headline-5' and @name='cardCvc']")
    cvc_input = self.chrome.find_element_by_xpath("//input[@class='pre-search-input headline-5' and @name='cardCvc']")
    cvc_input.clear()
    cvc_input.send_keys(cvc)
    self.wait_until_clickable(xpath="//button[@class='button button-continue']")
    self.chrome.find_element_by_xpath("//button[@class='button button-continue']").click()
    self.wait_until_clickable(xpath="//button[@class='button button-submit']")
    self.chrome.find_element_by_xpath("//button[@class='button button-submit']").click()
    print("Payment taken.")

This is my code that does not running. Before that error I encountered with another error like this: Refused to load the script 'http because it violates the following Content Security Policy directive with ChromeDriver Chrome headless Selenium.

I solved this error with this: self.chrome.execute_cdp_cmd("Page.setBypassCSP", {"enabled": True}) # to disable Contect Security Policy

Now i stuck at this error: The devicemotion events are blocked by feature policy. See https://github.com/WICG/feature-policy/blob/master/features.md#sensor-features polyfills.14f35e1be48465411559.js:1

I create my driver like this:

options = webdriver.ChromeOptions()
options.add_argument("--disable-web-security")
options.add_argument("--allow-running-insecure-content")
options.add_argument("--incognito")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument("user-data-dir=/Users/caner/Library/Application Support/Google/Chrome")
self.chrome = webdriver.Chrome(ChromeDriverManager().install(), options=options)
self.chrome.execute_cdp_cmd("Page.setBypassCSP", {"enabled": True})

Do you think i handle Content Security Policy in a right way. The difference between others pages and payment page is iframe. If you have any idea about this please let me know.

My Error is The devicemotion events are blocked by feature policy. at some specific page(payment page). I just told there might be possibility. However it might not be related to iframe, or such thing Content Security Policy. I was just guessing. Is there any one have idea about this error?

I didnt see the same issue those links. Ways to deal with #document under iframe (2 answers) How can I select a html element no matter what frame it is in in selenium? (2 answers) Refused to load the script because it violates the following Content Security Policy directive: script-src error with ChromeDriver Chrome and Selenium Also the last link i applied their solution it seems that it solves the CSP problem. But i have new problem (The devicemotion events are blocked by feature policy.). Thats why it should not be duplicated question.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Caner Taşan
  • 21
  • 1
  • 4
  • 1
    devicemotion events are for phones... anything that detects acceleration. Shouldn't affect you at all. I'm guessing these errors are generated by the page you are visiting which is running cross-domain scripts. In an iframe? Bypassing the content security policy is not a great idea... especially if you exposing any login info. There's a reason for restricting cross-origin scripts. – pcalkins Dec 10 '20 at 00:18
  • I agree,this seems like it's a browser console error, is that true? – DMart Dec 10 '20 at 01:15
  • If i want to run script in payment page, how can i able to do that without bypassing content security policy. @pcalkins Additional info: "Payments page fill my credit card and my billing address automatically, probably take this data with relation from my account.". – Caner Taşan Dec 10 '20 at 09:37
  • Yes, it is console error. @DMart – Caner Taşan Dec 10 '20 at 09:38
  • 1
    Yes i can see that clearly now. These console errors are happen when i normally enter the website as well. I thought that those errors occurs when i try to execute_script. As you said i dont bypass content security policy now. Also i can execute my down scroll script. Thanks a lot for your help @pcalkins – Caner Taşan Dec 10 '20 at 11:22
  • What was the solution here? – manymanymore May 12 '23 at 16:48

0 Answers0