0

I'm working on mobile automation on iOS platform using the following:

Selenium WebDriver: 2.47

Appium dot net driver: 1.4.0.3

Appium: 1.4.8

I want find a element using xpath and click on it. But I don't want to use the native methods of Selenium webdriver.

I want to perform this operation using javascript.

I have tried the following:

1

_driver.ExecuteScript("window.document.evaluate(\"//a[contains(text(),'Log In')]\", document.lastChild, null,XPathResult.ANY_TYPE, null).click()");

2

IList<IWebElement> buttons = _driver.FindElements(By.XPath("//a[contains(text(),'Log In')]"));
           _driver.ExecuteScript("arguments[0].click();", buttons[0]);

3

_driver.FindElement(By.XPath("//a[contains(text(),'Log In')]")).Click();

I'm able to switch to webviews but unable to click on this particular elment. In the second method, I can see that I can fetch the element but calling click() method is not clicking the element.

Thanks in advance. I'm stuck here for two days now.

update:

Here is the html of the button I want to click on:

<a class="btn btn-outline white slide-demo" data-slide-target=".slide-wrap">Log In</a>
Rameshwar
  • 541
  • 6
  • 22
  • You should probably provide the HTML for the element that you are trying to find. – JeffC Sep 01 '15 at 20:24
  • Why the requirement for not using native Selenium methods? – JeffC Sep 01 '15 at 20:24
  • It not my requirement. Its just that the native selenium methods are not working in iOS devices. I have also updated my question with the HTML. Please take a look into it. – Rameshwar Sep 02 '15 at 08:15

1 Answers1

0

The following example demonstrates a generic non-IE syntax for finding all H3 containing ‘XPath’ using an XPath query:

var result = document.evaluate("//h3[contains(text(),'XPath')]",
document.documentElement, null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)

        for (var i=0; i<result.snapshotLength; i++) {
            alert(result.snapshotItem(i).innerHTML)
        }

This link might be useful Also Check out This Tutorial

Community
  • 1
  • 1
  • The tutorial has 5 ways of querying an element excluding xpath. But there is no syntax for querying an element with xpath. A simple example is appreciated. Thanks – Rameshwar Sep 02 '15 at 10:40