首页 > 解决方案 > 移动仿真在 python 中找不到 xpath

问题描述

嘿伙计们,我在使用移动模拟器时无法定位元素

这是我的代码,错误表明该元素无法找到有关如何解决此问题的任何想法

from selenium import webdriver
from selenium.webdriver.chrome.options import *
from selenium.webdriver.common.keys import Keys
import os
import time

username = "hellogood111"
passwd = "hellogood11"
driverpth = "/Users/hugohanak/Downloads/chromedriver 3"
photopath = "/Users/hugohanak/Desktop/test.png"
phototext = "testing"

options = Options()
options.add_argument("--log-level=3")
options.add_argument("--silent")
#options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--disable-logging")
options.add_argument("--mute-audio")
#mobile_emulation = {"deviceName": "Nexus 5"}
#options.add_experimental_option("mobileEmulation", mobile_emulation)
options.add_argument('--user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1')
driver = webdriver.Chrome(executable_path=driverpth,options=options)
driver.get("https://www.instagram.com/accounts/login/?hl=tr")
time.sleep(3)
driver.find_element_by_xpath("//*[@id='react-root']/section/main/article/div/div/div/form/div[4]/div/label/input").send_keys(username)
time.sleep(0.5)
driver.find_element_by_xpath("//*[@id='react-root']/section/main/article/div/div/div/form/div[5]/div/label/input").send_keys(passwd)
time.sleep(0.5)
driver.find_element_by_xpath("//*[@id='react-root']/section/main/article/div/div/div/form/div[7]/button/div").click()
time.sleep(10)


driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/section/div/button').click()
driver.find_element_by_xpath('/html/body/div[4]/div/div/div[3]/button[2]').click()
driver.find_element_by_xpath('//*[@id="react-root"]/section/nav[2]/div/div/div[2]/div/div/div[3]/svg').send_keys(os.getcwd) + "/Users/hugohanak/Desktop/test.jpeg"

driver.quit()
print("finished")

标签: pythonseleniummobileemulation

解决方案


推荐阅读