首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Selenium Timeoutexception错误

Selenium Timeoutexception错误
EN

Stack Overflow用户
提问于 2018-06-17 15:51:35
回答 2查看 399关注 0票数 0

还在处理这个Instagram的问题,我真的需要你的帮助。

下面是我的代码:

代码语言:javascript
复制
input_button = wait(browser,10).until(EC.element_to_be_clickable((By.XPATH, 
'//button[@class ="chBAG"]')))

action=ActionChains(browser)
action.move_to_element(input_button)
action.click()
action.perform()

下面是HTML:

代码语言:javascript
复制
<button class="chBAG">Fermer</button>

但我得到了一个答案:

代码语言:javascript
复制
selenium.common.exceptions.TimeoutException: Message: 

有人能帮我解决这个问题吗?

Thx

EN

回答 2

Stack Overflow用户

发布于 2018-06-17 23:03:29

由于输入字段的泛型类,您会收到此错误。每次打开页面时,都会随机生成类名。那么如何修复它呢?例如:

假设你想要登录,你必须:

<>H213>G214G214单击email input字段

  • type information

  • click on

  • input field

  • type information
  • click on Log in button<代码>H213

示例代码可能如下所示:

代码语言:javascript
复制
# xpath will work every time because it is static
email_input = wait(browser,10).until(EC.element_to_be_clickable((By.XPATH, 
'//form/div[1]/div/div/input'))) # locate email input
email_input =ActionChains(browser)
email_input.move_to_element(email_input)
email_input.click()
email_input.sendKeys("email")
email_input.perform()

password_input = wait(browser,10).until(EC.element_to_be_clickable((By.XPATH, 
'//form/div[2]/div/div/input'))) # locate password input
password_input =ActionChains(browser)
password_input.move_to_element(password_input)
password_input.click()
email_input.sendKeys("password")
password_input.perform()

login_button = wait(browser,10).until(EC.element_to_be_clickable((By.XPATH, 
'//span/button'))) # locate login button
login_button_action=ActionChains(browser)
login_button_action.move_to_element(login_button )
login_button_action.click()
login_button_action.perform()

要在搜索栏中搜索内容,您必须执行以下操作:

单击输入字段并键入information

  • wait,直到results

  1. search
  2. 单击其中一个

代码:

代码语言:javascript
复制
import time # will be need below

search_input = wait(browser,10).until(EC.element_to_be_clickable((By.XPATH, 
"//input[@placeholder = 'Search']"))) # locate search input
search_input =ActionChains(browser)
search_input.move_to_element(search_input)
search_input.click()
search_input.sendKeys("fermer")
search_input.perform()

time.sleep(5) # wait 5 seconds until dropdown will appear

dropdown_menu = wait(browser,10).until(EC.element_to_be_clickable((By.XPATH, 
"//a[@href = '/explore/tags/fermermaid/']"))) # locate fermeraid
dropdown_menu = ActionChains(browser)
dropdown_menu.move_to_element(dropdown_menu)
dropdown_menu.click()
dropdown_menu.perform()
票数 0
EN

Stack Overflow用户

发布于 2018-06-17 23:32:20

根据您的要求,您可以使用以下代码:

它会在Instagram的搜索栏中搜索"This is testing“字符串。

代码语言:javascript
复制
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC 

driver = webdriver.Chrome(executable_path = r'D:/Automation/chromedriver.exe')
driver.get("https://www.instagram.com/accounts/login/")

username = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.NAME, "username")))

password = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.NAME, "password")))

username.send_keys("your username")
password.send_keys("your password")
driver.find_element_by_tag_name('button').click()

search = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//span[text()='Search']")))

search.click()
driver.find_element_by_xpath("//div[@role='dialog']/preceding-sibling::input").send_keys("This is testing")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50894723

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档