0

I try to "read and click" an Element that is not present on the Screen.

My current quick & dirty solution is to zoom the body to 90%, than all works fine in this case. But this cannot be the right solution.

IJavaScriptExecutor js = (IJavaScriptExecutor)webdriver;
js.ExecuteScript(string.Format("document.body.style.zoom='{0}%'", 90));

The Webside i am working with is: https://eatradingacademy.com/software/forex-historical-data/ Scroll a little down, push "Load Data" and in the table down of this Button i am reading something out and download Files.

I searched around and found the "Actions". There came no error up, but also nothing happens ... The XPath is correct.

var element11 = webdriver.FindElement(By.XPath("//*[@id='table-acquisition']/ tr[7]/td[2]"));
Actions actions = new Actions(webdriver);
actions.MoveToElement(element11);
actions.Perform();
//element11.Click();

Also I found some Code to scroll a little bid down, again no error, but also no effect (no scrolling).

IJavaScriptExecutor js = (IJavaScriptExecutor)webdriver;
js.ExecuteScript("javascript:window.scrollBy(250,350)");

What am i doing wrong in this both code examples? Or what is the solution to scroll to an Element that is currently not present shown on the Screen?

The complete Table is only readable if it is present on the Screen.

Who can help me?

Edit 1:

For more details in my question, here is c+p together was will be done in my code:

ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = false;

//// change Standart-Download-Ordner
//ChromeOptions options = new ChromeOptions();
//var downloadDirectory = GlobalVars.RootPath + GlobalVars.strSymbol;
//options.AddUserProfilePreference("download.default_directory", downloadDirectory);
//options.AddUserProfilePreference("download.prompt_for_download", false);
//options.AddUserProfilePreference("disable-popup-blocking", "true");

//// Selenium Driver starten:
//webdriver = new ChromeDriver(service, options);
webdriver = new ChromeDriver(service);

// Fenster auf Vollbild, damit keine Elemente verdecht werden
webdriver.Manage().Window.Maximize();

webdriver.Navigate().GoToUrl("https://eatradingacademy.com/software/forex-historical-data/");

// deactivate Request --NOT YET-- "Would you like to receive notifications on latest updates?"
webdriver.FindElement(By.Id("webpushr-deny-button")).Click();


//// Current solution: Zoom Browser Body
//IJavaScriptExecutor js = (IJavaScriptExecutor)webdriver;
//js.ExecuteScript(string.Format("document.body.style.zoom='{0}%'", 90));


// change to right iFrame
webdriver.SwitchTo().Frame(webdriver.FindElement(By.Id("data-app-frame")));
// Navigate to "Settings" ...
var objBrowserLink = webdriver.FindElement(By.XPath("//a[@class='nav-link panel-switch' and contains(text(), 'Settings')]"));
Actions actions = new Actions(webdriver);
actions.MoveToElement(objBrowserLink);
actions.Perform();
objBrowserLink.Click();

// Change settings
webdriver.FindElement(By.Id("btn-reset-settings")).Click();
webdriver.FindElement(By.XPath("//select[@id='select-max-bars']/option[contains(text(), '200 000')]")).Click();
webdriver.FindElement(By.XPath("//select[@id='select-timezone']/option[contains(text(), '(GMT+02:00) Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius')]")).Click();
webdriver.FindElement(By.Id("input-server")).Clear();
webdriver.FindElement(By.Id("input-server")).SendKeys("AM Premium Data");

// Navigate to -Acquisition-
var objBrowserLink = webdriver.FindElement(By.XPath("//a[@class='nav-link panel-switch' and contains(text(), 'Acquisition')]"));
Actions actions = new Actions(webdriver);
actions.MoveToElement(objBrowserLink);
actions.Perform();
objBrowserLink.Click();

// Select Format to Download
webdriver.FindElement(By.XPath("//select[@id='select-format']/option[contains(text(), 'Expert Advisor Studio (JSON)')]")).Click();

// Click Button Load Data
webdriver.FindElement(By.Id("btn-load-data")).Click();

// --> Here starts my current problem:
// #####################################

// Test if switch will help again
//webdriver.SwitchTo().Frame(webdriver.FindElement(By.Id("data-app-frame")));
var element11 = webdriver.FindElement(By.XPath("//*[@id='table-acquisition']/ tr[7]/td[2]"));
Actions actions = new Actions(webdriver);
actions.MoveToElement(element11);
actions.Perform();
element11.Click();
//Thread.Sleep(1000);

// now follows a for ... The 2 lines down shoud do what is needed ...
//for (int i = 1; i < 8; i++)

string strXPath_Download_Table = "//*[@id='table-acquisition']/ tr[7]/td[6]";
webdriver.FindElement(By.XPath(strXPath_Download_Table)).Click();
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
Dragon
  • 49
  • 7
  • What error are you getting when using actions? It feels like i've explained this question to you almost 100% identical in this post. https://stackoverflow.com/questions/72364676/c-sharp-selenium-navigate-to-statistics-on-specifig-page – Ruben May 28 '22 at 13:45
  • Hello again, I remember you and your spended time in my requests. Thank you for that! Just again. I got now the Exception ""OpenQA.Selenium.MoveTargetOutOfBoundsException"" I am in the right IFrame ... Never moved out". Also testet to switch in again ... The Method Actions is tested as described in my original Post with your code ; ) – Dragon May 28 '22 at 14:51
  • Regarding your request i testet it again ... When i switch again to the IFrame i got another Error: "OpenQA.Selenium.NoSuchElementException" Without switch IFrame i got the error as posted before – Dragon May 28 '22 at 15:04
  • I edit my original Post to give out my complete code to reproduce. Hopefully someone see what i am doing wrong. – Dragon May 28 '22 at 18:21

0 Answers0