Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
428 views
by Contributing Tester (53 points)
retagged by

Hi, I run this next code but response is not correct. What is wrong?

from selenium import webdriver

driver = webdriver.PhantomJS()

driver.get('google.com')

print(driver.page_source)

response:

<html><head></head><body></body></html>

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer

Have you tried using http://google.com ?

 

from selenium import webdriver

driver = webdriver.PhantomJS()

driver.get('http://google.com')

print(driver.page_source)
 
Hope that helps! Let me know in comment.
by Contributing Tester (53 points)
Yes, it works. Thanks a lot. But after that I tried https://xcoinx.com/en/ and this one doesn't work, also I tried to change headers, still nothing. Why does it open some sites and other don't?
by The go-to Tester (181 points)
Can you post your code for https://xcoinx.com/en/ ?
by Contributing Tester (53 points)
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
    "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 "
    "(KHTML, like Gecko) Chrome/15.0.87"
)
driver = webdriver.PhantomJS(desired_capabilities=dcap)

driver.get('https://xcoinx.com/en/')

print(driver.page_source)

This is the last one I have tried, maybe headers are not correct, never worked with PhantomJS
by Contributing Tester (53 points)
here's the working code to get page source:
from selenium import webdriver


driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true', '--ssl-protocol=TLSv1'])

driver.get('https://xcoinx.com/en/')

print(driver.page_source)

important part of code: service_args=['--ignore-ssl-errors=true', '--ssl-protocol=TLSv1']
by The go-to Tester (181 points)
I am glad that worked! Thank you for sharing your solution.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...