Hack Forums
[C] Selenium variable sendkeys - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] Selenium variable sendkeys (/showthread.php?tid=6134011)



Selenium variable sendkeys - Perileos - Jan 15, 2021

Hi,

So I'm trying to use xpath to find a specific number on a page and this to relay on the send function.

Code
var woodmarketread = drv.FindElement(By.XPath("//*[@id=\"premium_exchange_stock_wood\"]"));
            var woodmarketinput = drv.FindElement(By.XPath("//*[@id=\"premium_exchange_buy_wood\"]/div[1]/input"));

            woodmarketinput.SendKeys(woodmarketread);

How could I make this work?


RE: Selenium variable sendkeys - Exalted - Jan 15, 2021

Use .getText() or .getAttribute(String attr) on woodmarketread to get the right value.

Next do .SendKeys(woodmarketread) on woodmarketinput to fill in the value and compelete with a .SendKeys(Keys.Return) on woodmarketinput or click on the appropriate button.


RE: Selenium variable sendkeys - Perileos - Jan 15, 2021

(Jan 15, 2021 02:58 PM)Exalted Wrote:  Use .getText() or .getAttribute(String attr) on woodmarketread to get the right value.

Next do .SendKeys(woodmarketread) on woodmarketinput to fill in the value and compelete with a .SendKeys(Keys.Return) on woodmarketinput or click on the appropriate button.

Yep this worked. Cheers, had to convert var to string though.

Looks like this now:
Code
var woodmarketread = drv.FindElement(By.XPath("//*[@id=\"premium_exchange_stock_wood\"]")).Text;
var woodmarketinput = drv.FindElement(By.XPath("//*[@id=\"premium_exchange_buy_wood\"]/div[1]/input"));
woodmarketinput.SendKeys(Convert.ToString(woodmarketread));