Question

I am learning selenium. I am trying to download my facebook data to my local using selenium. I am not able to click on the Download Archive Button in facebook. I tried the below option.

driver.findElement(By.xpath("html/body/div[2]/div[2]/div[1]/div/div[2]/div/div/div/div[1]/form/button")).click;

Source Code :

<form id="u_jsonp_3_0" onsubmit="return window.Event && Event.__inlineSubmit && Event.__inlineSubmit(this,event)" method="post" action="https://www.facebook.com/dyi/download?x=Adm4f5xH8GLlCGdN" rel="async">
<input type="hidden" autocomplete="off" value="AQBnnWIM" name="fb_dtsg">
<button class="_42ft _42fu selected _42gz _42gy" type="submit" value="1">Download Archive</button>
</form>

Any ideas would be really helpful.

No correct solution

OTHER TIPS

First and foremost thing is, DO NOT TRY TO BUILD XPATH like this. I assume that causes you these issues. Better try something as follows,

//a[@type='submit' and contains(., "Download Archive")]

and if you still need some help, please do share your stack trace or exception that you got.

First of all try to avoid such long xpath's, the page might change dynamically causing your test case to fail. You can make use of attributes like id,name,class..etc to get to them directly.

If you trying to learn, facebook or google is not a good place to start with,because they have dynamic id's (id's change everytime the page is loaded).

But in the above case,this should work :

driver.findElement(By.xpath("//button[contains(., 'Download Archive')]")).click();

or

You can use Implicit or Explicit Wait to wait for elements visibility,

new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[contains(., 'Download Archive')]"))).click();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top