d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Selenium / Xpath Question
Add Reply New Topic New Poll
Member
Posts: 9,525
Joined: Nov 5 2005
Gold: 1,338.00
Dec 9 2015 10:13pm
Ok, so suppose you're writing a selenium script that opens a website, logs in, navigates to a page where you enter in a search query, enters some stuff, presses enter, and you get back a page full of tables and cells (tr / td). You want the value of what's in a particular cell.

The bad news: none of the cells have any identifiers (like, no id = ?? or class = ??). So you can't just findElement(By.id("thecellsid").

The good news: you know that typing in that query will yield the same table every single time.

So I figured, was there some way to find it by its location on the webpage?? On firefox, there is a function called "Copy Unique Selector" that gives me the XPath for the element.

Well, after some googling, I discovered that selenium has a findElement(By.xpath("")) method as well as a By.cssSelector method, but the formats look a different.

In other words, the path isn't really copy/paste-able. I was wondering if there was some method or algorithm to convert it, or if maybe there's an easier way to do this.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Member
Posts: 9,525
Joined: Nov 5 2005
Gold: 1,338.00
Dec 9 2015 10:32pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll