Skip to content

Replies

0
Azhar uddin
Azhar uddin answered on Mar 14, 2018 7:54 AM

XPath is okay, but I prefer CSS Selector as it tends to yeild less brittle selectors (not so location in the DOM based, but still can be). To get one in Chrome:

  1. Right-click on the element and select 'Inspect'
  2. Right-click on the element in the DOM explorer of DevTools
  3. Select "Copy" > "Copy selector"

So then your code would look something like:

IWebElement element =  driver.FindElement(By.CssSelector("paste_the_selector_here"));
// Click via Selenium's Click method
element.Click();
// Or, click via JavaScript
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click()", element);

Also, instead of clicking the <span> you may want to click on the <a> instead as it has an onclick event listener.

If the selector includes an ID for a parent that is dynamic, then you'll want to remove it. To remove it, find the element with that ID in the DevTool's Element tab. Double-click on the id="..." part and delete the whole thing. Now get the selector for the child element.

This example

<div id="ctl00_NavBarAdmin_WebDataMenu1"> // <- Parent div html
#ctl00_NavBarAdmin_WebDataMenu1 > ul > li:nth-child(2) > ul > li.igdm_MenuItemVertical.igdm_MenuItemVerticalParent.igdm_Me‌​nuItemVerticalSelect‌​ed > a

Might become

<div> // <- Parent div HTML
div > ul > li:nth-child(2) > ul > li.igdm_MenuItemVertical.igdm_MenuItemVerticalParent.igdm_Me‌​nuItemVerticalSelect‌​ed > a 
0
Azhar uddin
Azhar uddin answered on Feb 21, 2018 11:55 AM

You may try any one of them:

Solution 1:

Step 1: Connect the Phone/Dongle to the COM Port via USB.

Step 2: Call the code for fetching sms via smslib.jar

Sample Code to fetch sms:

public void sendSMS() throws Exception{
    OutboundNotification outboundNotification = new OutboundNotification();
    SerialModemGateway gateway = new SerialModemGateway("modem.com5", "COM5", 9600, "ZTE", "COM5");
    gateway.setInbound(true);
    gateway.setOutbound(true);
    gateway.setSmscNumber("+91XXXXXXXXXX"); // 10-digit Mobile Number
    Service.getInstance().setOutboundMessageNotification(outboundNotification);
    Service.getInstance().addGateway(gateway);
    Service.getInstance().startService();
    OutboundMessage msg = new OutboundMessage(ExcelConnect.strSMSTo, ExcelConnect.strSMSText);
    Service.getInstance().sendMessage(msg);
    System.out.println(msg);
    System.out.println(ExcelConnect.strSMSTo + "-" + ExcelConnect.strSMSText);
    Service.getInstance().stopService();
    Service.getInstance().removeGateway(gateway);
}

Step 3: Parse sms to get the OTP from the fetched list by latest received sms

.

Solution 2:

Step 1: Connect the android phone / iphone.

Step 2: Automate the SMS App in either of the phone, if its android – automate SMS app via appium(or any other automating app) or if its iphone – automate its SMS app feature.

to get the SMS and parse it to get the OTP

.

Solution 3:

Step 1: Register for the HTTP SMS Gateway(Most of them provide paid API Call with very few free API Calls for testing).

Step 2: Call the method to fetch SMS.

Step 3: Parse the message(after sorting it by latest received sms) to get the OTP

.

These three ways you can get the OTP and then you can send it to you Web Application.

.

Solution 4:

Get the OTP from DB, if its in-house application or if it can be accessed.

.

'Solution 3 and Solution 4' being most efficient and it doesn't have any dependency on sms receiving platforms.

.

Solutions consolidated below: