0

I am trying to automate the Trello Activity extension, and I am trying to automatically press the button "Export to CSV" with Selenium.

And my code, I am trying to get the button with xPath:

driver.FindElement(By.XPath("//[@id=\'content\']/div/div[1]/div[1]/div[2]/span[1]/div/button")).Click();

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));

wait.Until(ExpectedConditions.ElementExists(By.XPath("/html/body/section/div[1]/ul/li[1]/button")));
driver.FindElement(By.CssSelector("body > section > div:nth-child(1) > ul > li:nth-child(1) > button")).Click();`

Here is the button:

enter image description here

And this is its html:

enter image description here

I am trying to automate Trello Activity extension, and I am trying to automatically press the button "Export to CSV" with Selenium.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Screenshots of the UI are great, screenshots of code or HTML are not. Please read why [a screenshot of code/HTML is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Paste the code/HTML and properly format it instead. – JeffC Feb 26 '23 at 02:13

1 Answers1

0

The element with text as Export to CSV is with an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired ElementToBeClickable().

  • You can use either of the following Locator Strategies:

  • Using CssSelector:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.CssSelector("iframeCssSelector]"));
    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("body > section > div:nth-child(1) > ul > li:nth-child(1) > button"))).Click();
    
  • Using XPath:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.XPath("iframeXPath"));
    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//html/body/section/div[1]/ul/li[1]/button"))).Click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352