当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Wrong image/link relative paths in Selenium

问题描述:

I am trying to load a page in my domain and then analyze the content of the page (getting the text/image/etc. and their positions). I tried my code on 2-3 different domains and it works fine. Only on one of the domains, when I am loading my page "subdomain.domain.com/page", selenium uses a wrong base url and load all the relative paths in a wrong way. For instance, instead of loading the following image:

subdomain.domain.com/my_image.jpg

it tries to load this path, and it clearly fails:

subdomain.domain.com/page/my_image.jpg

I first employed Selenium and PhantomJS and saw the issue. Then, I switched to Firefox on Xvfb and Selenium, but I still see the same issue. Here is how I load the page:

FirefoxBinary binary = new FirefoxBinary(new File("/usr/bin/firefox"));

binary.setEnvironmentProperty("DISPLAY",System.getProperty("lmportal.xvfb.id",":10"));

FirefoxProfile profile = new FirefoxProfile();

profile.setPreference("general.useragent.override", userAgent);

driver = new FirefoxDriver(binary,null);

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.get(url);

Any thoughts?

网友答案:

I have found where was the issue. I was adding a '/' at the end of the urls. Apparently, it messes up those relative paths. Thus, to solve this issue you may load:

subdomain.domain.com/page

instead of:

subdomain.domain.com/page/
分享给朋友:
您可能感兴趣的文章:
随机阅读: