ToniMahoni101
ToniMahoni101

Reputation: 23

find element by xpath - selenium propper formating

I have a button on a Webpage that needs to be pressed so that a data file can be rebuilt to then dowload this file. I don't know any HTML, so I am unsure which variables are needed to get the driver.find_element_by_xpath() to correctly locate the button on the Webpage

The HTML code of the website is the following:


<html><head><title>HPC Data Directory</title><META HTTP-EQUIV="refresh" CONTENT="60"><META HTTP-EQUIV="Pragma" CONTENT="no-cache"><META HTTP-EQUIV="Expires" CONTENT="-1"></head><body bgColor=#ffffff leftMargin=0 topMargin=10 marginwidth="0" marginheight="0"><div align=center style="width: 833; height: 470"><table style="border: 1px solid #000080" height=384 cellSpacing=0 cellPadding=0 width="815"><tbody><tr bgColor=#EEEEEE><td style="border-bottom: 1px solid #000080" vAlign=bottom noWrap height=70 margin=50 width="815"><h2 align="center"><font face="verdana" color="#006699">HPC Data Web Server</font></h2></td></tr><tr><td colSpan=5 height=380 width="815" vAlign=top background="llblue.jpg" style="background-repeat: repeat-y;"><div align=center><center><font face="verdana"><table width="90%" border=0 align=center><tbody><tr><td width="95%"><h2 align=center><br>Data File Directory</h2><table border=0 width=750><tr align=left bgcolor=#aaccff><th width=50%>File Name</th><th width=15%>Records</th></tr><td align=left><a href="/DATA.XLS" target="_blank">DATA.XLS</a></td><td align=left>10000</td><br><br></table><form name=form1 method=post><br><br><br><input type=hidden name=BuildFile value="Build"><br><p>Click link above to download data file.</p><input type=button name=Export value="Rebuild Data File" onclick="submit()"></form></td></tr></tbody></table></font></center></div></td></tr><tr><td colSpan=5 height=20 width="805" background="llblue.jpg" style="background-repeat: repeat-y;"></td></tr></tbody></table></div></body></html>

I gathered that the code for the button for "Rebuilding the Data", which needs to be done before each download, is this one:

<input type=button name=Export value="Rebuild Data File" onclick="submit()">

How do I properly format these variables into something that the driver.find_element_by_xpath() can use to locate and press the button? Is this even the xpath thing? Or should I be using another method to locate the button like css.

Upvotes: 0

Views: 103

Answers (2)

Ishan
Ishan

Reputation: 211

Xpath helps you navigate to any element in the html

You can use either of the following xpaths:

  • //input[@value='Rebuild Data File']
  • //input[@name='Export']
  • //input[@name='Export' and @value='Rebuild Data File']

More info on: https://www.guru99.com/xpath-selenium.html

Upvotes: 3

SeleniumUser
SeleniumUser

Reputation: 4177

Can you please try below xpath :

   WebElement element = (new WebDriverWait(driver, 10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@type='button'][@value='Rebuild Data File']")));
   element.click();

**Don forget to import **

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

Upvotes: 0

Related Questions