0

This is a script on app automation that I am executing on BrowserStack.

Here is my code:

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

userName = "xxxxx"
accessKey = "yyyyy"

desired_caps = {
    "build": "Python android login",
    "device": "Samsung Galaxy S8 Plus",
    "app": "bs://e761bd35add7e1da33f6a4c480bf91a96dcd3382",
    'autoAcceptAlerts': 'true',
    'name' :'App test2'
}

try:

    driver = webdriver.Remote("https://" + userName + ":" + accessKey + "@hub- 
    cloud.browserstack.com/wd/hub", desired_caps)
    
    driver.implicitly_wait(30)
    driver.find_element_by_xpath("//oj-button-text[contains(text(),'Agree')]").click()
    driver.find_element_by_id("oj-button-1401427062-1|text").click()
    print("Click completed on agree buton")

except:
    raise

Here are the properties:

enter image description here

Button Properties
Name SPAN
Type 1
Id oj-button-1401427062-1
Class oj-button-text
Text Agree
X 854.6563110351562
Y 2079.0
W 207.34375762939453
H 41.000000953674316
BgColor rgba(0, 0, 0, 0)
Visibility visible
Display inline
Overflow hidden
Position static
CssSelector #oj-button-1401427062-1
Xpath //span[@id="oj-button-1401427062-1
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • 3
    Welcome to Stack Overflow. Please include the full traceback error. – ewokx May 04 '22 at 07:33
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 04 '22 at 08:20
  • It’s most likely a span and not a oj-button tag which is given in the xpath. – Arundeep Chohan May 04 '22 at 09:26

1 Answers1

0

As per the element properties, it's a <span> element with class as oj-button-text and text as Agree.


Solution

To click on the element with text as Agree you can use either of the following locator strategies:

driver.find_element_by_xpath("//span[contains(.,'Agree')]").click()

or

driver.find_element_by_xpath("//span[@class='oj-button-text' and contains(., 'Agree')]").click()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352