我不是程序员,但我喜欢自动化的东西,并且仍然对此有所了解。请告诉我。
这是我的问题: 我使用Python Selenium登录此网站Anywhereconference.com,并尝试以主持人模式登录,但未找到那些元素。问题是,登录容器隐藏在主持人容器下,需要首先单击。
代码
ntt = webdriver.Chrome()
ntt.get("https://anywhereconference.com")
ntt.set_window_size(1500, 800)
ntt.implicitly_wait(10)
mode = ntt.find_element_by_xpath('//*[@id="arka-login-moderator-type-button-header"]').click()
login = ntt.find_element_by_xpath('//*[@id="arka-login-moderator-weblogin"]')
login.send_keys('XXX')
login.send_keys(Keys.ENTER)
错误
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="arka-login-moderator-type-button-header"]"}
(Session info: chrome=84.0.4147.89)
点击元素
div id="arka-login-moderator" class="arka-login-button arka-login-moderator-button ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left ui-corner-right arka-login-moderator-selected ui-state-active ready">
<span class="ui-button-text">
div id="arka-login-moderator-type-button-header" class="arka-login-type-button-header">I'm a moderator / admin</div
div id="arka-login-moderator-type-button-text" class="arka-login-type-button-text">Start or schedule a meeting</div
</span>
我也尝试使用另一种方法,但是仍然相同,但是使用Selenium IDE扩展没问题。
示例1
WebDriverWait(ntt, 20).until(
EC.element_to_be_clickable((
By.XPATH, '//*[@id='arka-login-moderator-type-button-header']")))
.click()
示例2 JavaScript
mode = ntt.find_element_by_xpath(
'//*[@id="arka-login-moderator-type-button-header"]')
.click()
ntt.execute_script("$(arguments[0]).click();", mode)
答案 0 :(得分:1)
尝试下面的代码,页面上存在iframe,您需要先切换ifraame,然后才能处理网络元素:
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome(executable_path=r" path to chromedriver.exe")
driver.get("https://www.anywhereconference.com/")
driver.maximize_window()
iframe = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.NAME, 'globalFrameCenter')))
driver.switch_to.frame(iframe)
wait = WebDriverWait(driver, 30)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@id='arka-login-moderator']//span"))).click()
actionChains = ActionChains(driver)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='arka-login-moderator-weblogin']"))).send_keys("Test")
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='arka-login-moderator-pin']"))).send_keys("Test")
输出:
答案 1 :(得分:0)
按如下所示更改xpath
mode = ntt.find_element_by_xpath("//*[@id='arka-login-moderator-type-button-header']").click()
login = ntt.find_element_by_xpath("//*[@id='arka-login-moderator-weblogin']")