How to automate office 365 excel using selenium ?

58 views
Skip to first unread message

Francis Tabora

unread,
Oct 30, 2024, 7:44:39 AM (13 days ago) Oct 30
to Selenium Users
Hi everyone, 

I'm currently an intern, and I'm facing some issues I'd appreciate assistance. My objective is to implement code to automate excel online using selenium but it's not working, and I'm unsure how to move forward.

Thank you in advance for you help.

You can see my code below : 

package com.sac.fpa80.FPA80.tests;

import com.sac.web.ui.Selenium;
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;
import org.testng.annotations.Test;

import com.sac.commons.abs.MyDriver;
import com.sac.fpa80.FPA80.abs.AbstractTest;
import com.sac.e2e.pages.LoginPage;
import com.sac.web.ui.WebDriverFactory;

import java.time.Duration;


public class myTest extends AbstractTest {

MyDriver _driver;
LoginPage _loginPage;
Selenium selenium;

@Test(description="FPA80 Login Test")

public void login() {
/*
* Initialisations :
* - Driver
* - Page login
* - Selenium
* */
_driver = WebDriverFactory.getWebDriver(configs);
_loginPage = new LoginPage(_driver);
selenium = new Selenium(_driver, MyDriver.class);

//-----------------------------------------------------------------------

// Maximize the window
_driver.getDriver().manage().window().maximize();

// NNavigate to url
_loginPage.navigate(environments.getString("myUrl"));

// Tester si selenium est nulle
if (selenium != null) {
this.selenium.click("Btn_Log");
} else {
System.out.println("L'instance est null");
}

//-----------------------------------------------------------------------

// Redirection
WebDriver driver = _driver.getDriver();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(60));
wait.until(ExpectedConditions.urlToBe("https://www.office.com/?auth=2"));

// waiting for the search bar
this.selenium.waitForAnyOfTheElementToAppear("searchInput");

// waiting for the element to clic on it
//WebDriverWait wait = new WebDriverWait(_driver.getDriver(), Duration.ofSeconds(15));
WebElement searchInput = wait.until(ExpectedConditions.elementToBeClickable(By.id("ms-searchux-input-0")));

// Sending the text
searchInput.sendKeys("memberSelector_dimension");

// waiting for the button element
this.selenium.waitForAnyOfTheElementToAppear("Btn_excel");
this.selenium.click("Btn_excel");

// It's not working
this.selenium.waitForAnyOfTheElementToAppear("BtnAnalytics");
this.selenium.click("BtnAnalytics");

}
}

Here's my locators:

#DefaultLocator
BtnAnalytics=button[data-unique-id='AddinTab0']
Btn_Log=//*[@id='hero-banner-sign-in-microsoft-365-link']
searchInput=//*[@id="ms-searchux-input-0"]
Btn_excel=//*[@id="file"]/li[2]/div/div/

ddlionx

unread,
Oct 31, 2024, 4:49:47 AM (13 days ago) Oct 31
to seleniu...@googlegroups.com
How is it not working? Are you getting errors, or what? This code looks incomplete as I don’t know what MyDriver.class is among other things. 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/selenium-users/18a2b2ac-f3d0-437c-b13a-0ca017c3eca3n%40googlegroups.com.

Francis Tabora

unread,
Oct 31, 2024, 5:38:47 AM (13 days ago) Oct 31
to Selenium Users
You can see the code for MyDriver.class below :
package com.sac.commons.abs;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.events.EventFiringDecorator;
import org.openqa.selenium.support.events.WebDriverListener;

import io.appium.java_client.AppiumDriver;
import lombok.Getter;
import lombok.Setter;
/**
* WebDriver and AppiumDriver Wrapper class
* @author I356181
*
*/
@Getter
@Setter
public class MyDriver {
WebDriver driver;
AppiumDriver appDriver;
String driverKey;
boolean preserveSession=false;

public void decorateWithEvent(WebDriverListener listener) {
if(this.driver!=null) {
this.driver=new EventFiringDecorator<WebDriver>(listener).decorate(this.driver);
}
}
}

The code is not able to click on the button when I navigate to the excel online page

In the screenshot below, I want to clic on SAP Analytics or another button too.
Screenshot 2024-10-29 175948.png

Vinaysimha Varma Yadavali

unread,
Nov 10, 2024, 7:19:01 AM (2 days ago) Nov 10
to Selenium Users

To help troubleshoot your code for automating Excel Online with Selenium, here are some tips and suggestions based on your code snippet:

  1. Review Element Locators: Ensure that all your locators are up-to-date and correctly correspond to elements on the page. For example, the Btn_excel locator is likely causing issues because it's incomplete (//*[@id="file"]/li[2]/div/div/ should have a complete path to the element or an alternative locator strategy like a unique ID or class).

  2. Check Element Availability: Sometimes, elements can be hidden in iframes or require specific focus. You might need to switch to an iframe if the target elements are inside one. To check, inspect the page structure and use driver.switchTo().frame(frameElement); before locating elements within the iframe

  3. Debugging with Browser Developer Tools: Test each locator individually in the browser’s console to ensure they match the intended elements.

// Check if BtnAnalytics is clickable before proceeding
WebElement btnAnalytics = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[data-unique-id='AddinTab0']")));
btnAnalytics.click();
Reply all
Reply to author
Forward
0 new messages