问题描述
大家好,我需要帮助,问题是我有一个 selenium python 自动化脚本,我在桌面上工作正常,但现在我想在移动浏览器堆栈中进行测试,任何人都知道我们如何在其中进行测试
driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")
driver.get("https://catevolution.com.au/litter-robot-3-connect.html")
driver.maximize_window()
time.sleep(3)
action = ActionChains(driver)
action.move_to_element(driver.find_element_by_xpath(
"//header/div[2]/div[1]/div[2]/div[2]/div[2]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/ul[1]/li[1]/a[1]/span[1]/strong[1]")).perform()
time.sleep(3)
action.move_to_element(driver.find_element_by_link_text("Litter-Robot Connect")).click().perform()
time.sleep(3)
driver.execute_script("window.scrollTo(0,350);")
driver.switch_to.frame("zip-widget zip-widget__iframe zip-widget__iframe--type-productwidget")
dropdown = Select(driver.find_element_by_id("input-option240"))
dropdown.select_by_visible_text("Grey (SKU: LR3C-1200 ) ")
driver.switch_to.default_content()
time.sleep(5)
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
driver.quit()
解决方法
这应该会有所帮助:https://www.browserstack.com/docs/automate/selenium/migrate-existing-test-suites#python
还有一个示例代码。您只需为要运行测试的设备设置功能。
能力页面:https://www.browserstack.com/automate/capabilities
作为旁注,删除 driver.maximize_window()
。您无法最大化移动设备上的窗口。这将引发异常。
大家,我必须使用相同的步骤,但它没有在浏览器上运行 _stack 并给我错误我也使用正在运行的 appium 服务器。我现在能做什么请告诉我请这里是图片和代码的描述链接请检查并告诉我?
from selenium.webdriver.common.keys 导入密钥 从 selenium.webdriver.common.desired_capabilities 导入 DesiredCapabilities
这两个选项没有集成在 selenium 中
代码:
import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.select import Select
BROWSERSTACK_URL = 'https://muhammadyousufkh1:Vs1JXyvaPcPzhEK8mqmy@hub-cloud.browserstack.com/wd/hub'
desired_cap = {
'browserName': 'android','device': 'Samsung Samsung Galaxy Note 10','realMobile': 'true','os_version': '9.0','name': "muhammadyousufkh1's First Test"
}
driver = webdriver.Remote(
command_executor='https://muhammadyousufkh1:Vs1JXyvaPcPzhEK8mqmy@hub-cloud.browserstack.com/wd/hub',desired_capabilities=desired_cap
)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("mobileEmulation",desired_cap)
driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")
driver.get("https://catevolution.com.au/litter-robot-3-connect.html")
time.sleep(3)
action = ActionChains(driver)
action.move_to_element(driver.find_element_by_xpath(
"//header/div[2]/div[1]/div[2]/div[2]/div[2]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/ul[1]/li[1]/a[1]/span[1]/strong[1]")).perform()
time.sleep(3)
action.move_to_element(driver.find_element_by_link_text("Litter-Robot Connect")).click().perform()
time.sleep(3)
driver.execute_script("window.scrollTo(0,350);")
driver.switch_to.frame("zip-widget zip-widget__iframe zip-widget__iframe--type-productwidget")
dropdown = Select(driver.find_element_by_id("input-option240"))
dropdown.select_by_visible_text("Grey (SKU: LR3C-1200 ) ")
driver.switch_to.default_content()
time.sleep(5)
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
driver.quit()