简体   繁体   English

无法在 appium 中的 twitter LoginPage 上找到元素

[英]Unable to locate an element on twitter LoginPage in appium

通过 appium 桌面的 Twitter 登录页面

I am trying to locate "Log In" on twitter loginpage using appium, but i see "Have an account already?Log In" is clubbed under one locator and as expected this locator is not accepting "tap" operation of appium desktop as well.我正在尝试使用 appium 在 twitter 登录页面上找到“登录”,但我看到“已经有帐户?登录”在一个定位器下,并且正如预期的那样,该定位器也不接受 appium 桌面的“点击”操作。

Therefore, I'm not unable to automate twitter logIn operation in appium.因此,我无法在 appium 中自动执行 twitter logIn 操作。

Can someone please advise how to do the same?有人可以建议如何做同样的事情吗?

If Tap by coordinates is working in Appium Inspector on the element (not just regular tap, which selects an element, but tap by coordinates, which taps the absolute location) then you can use that solution to tap Log in text.如果在元素上的 Appium Inspector 中Tap by coordinates (不仅仅是常规点击,它选择一个元素,而是按坐标点击,它点击绝对位置),那么您可以使用该解决方案点击Log in文本。

First, we want to locate the element, then move by a small x axis offset (about 20px) over to the 'Log In' link.首先,我们要定位元素,然后移动一个小的x轴偏移量(大约 20 像素)到“登录”链接。

Depending on the language you are using, you can use TouchActions class to accomplish this:根据您使用的语言,您可以使用TouchActions class 来完成此操作:

// get the web element for link
IWebElement logInLink = driver.FindElement(By.XPath("//*[contains(@text, 'Log in')]"));

// get the x,y coordinates for the link
int xCoordinate = logInLink.Coordinates.LocationOnScreen.X;
int yCoordinate = logInLink.Coordinates.LocationOnScreen.Y;

// perform action that moves to coordinates, and taps 20 pixels to the right
new TouchAction(driver).MoveTo(xCoordinate + 20, yCoordinate).Press().Release().Perform();

You will probably have to play around with the offset value + 20 here and try out 10 , 30 , etc. You can also get the coordinates location using 'Tap by coordinates' in Appium inspector, and then debug your code to get the coordinates of the WebElement, and adjust your offset to make the x coordinate of the element match the x coordinate of the desired tap location.您可能必须在这里使用偏移值+ 20并尝试1030等。您还可以使用 Appium 检查器中的“按坐标点按”获取坐标位置,然后调试代码以获取坐标WebElement,并调整您的偏移量以使元素的 x 坐标与所需点击位置的 x 坐标相匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM