标签: webdriverwait

Python 中的 Selenium:“NoSuchElementException:消息:没有这样的元素:无法找到元素”

我尝试在第一个 id 块中输入“abc”,在第二个密码块中输入“cdef”。

但是,出现了底部的错误代码。

from selenium import webdriver
driver.get('http://sugang.korea.ac.kr')
Run Code Online (Sandbox Code Playgroud)

我添加了隐式等待,以防止代码在页面完全加载之前执行。

driver.implicitly_wait(30)

添加用户名和密码的代码如下:

driver.find_element_by_name('id').send_keys('abc') driver.find_element_by_name('pw').send_keys('cdef')

但我收到以下错误:

NoSuchElementException:消息:没有这样的元素:无法找到元素:{“method”:“id”,“selector”:“id”}

python selenium frame selenium-webdriver webdriverwait

7
推荐指数
2
解决办法
3万
查看次数

如何通过 Selenium Python 点击​​某个元素

我正在尝试使用 selenium 浏览器 python 获取 facebook 帐户的数据,但无法找到我可以在单击导出按钮时查找的元素。

请参阅随附的屏幕截图在此输入图像描述

我尝试过,但似乎给我的班级带来了错误。

def login_facebook(self, username, password):
    chrome_options = webdriver.ChromeOptions()
    preference = {"download.default_directory": self.section_value[24]}

    chrome_options.add_experimental_option("prefs", preference)
    self.driver = webdriver.Chrome(self.section_value[20], chrome_options=chrome_options)
    self.driver.get(self.section_value[25])

    username_field = self.driver.find_element_by_id("email")
    password_field = self.driver.find_element_by_id("pass")

    username_field.send_keys(username)
    self.driver.implicitly_wait(10)

    password_field.send_keys(password)
    self.driver.implicitly_wait(10)

    self.driver.find_element_by_id("loginbutton").click()
    self.driver.implicitly_wait(10)

    self.driver.get("https://business.facebook.com/select/?next=https%3A%2F%2Fbusiness.facebook.com%2F")
    self.driver.get("https://business.facebook.com/home/accounts?business_id=698597566882728")
    self.driver.get("https://business.facebook.com/adsmanager/reporting/view?act="
                    "717590098609803&business_id=698597566882728&selected_report_id=23843123660810666")
    # self.driver.get("https://business.facebook.com/adsmanager/manage/campaigns?act=717590098609803&business_id"
    #                 "=698597566882728&tool=MANAGE_ADS&date={}-{}_{}%2Clast_month".format(self.last_month,
    #                                                                                      self.first_day_month,
    #                                                                                      self.last_day_month))

    self.driver.find_element_by_id("export_button").click()
    self.driver.implicitly_wait(10)
    self.driver.find_element_by_class_name("_43rl").click()
    self.driver.implicitly_wait(10)
Run Code Online (Sandbox Code Playgroud)

您能告诉我如何单击“导出”按钮吗?

selenium xpath css-selectors python-2.7 webdriverwait

7
推荐指数
1
解决办法
6816
查看次数

如何使用 Selenium 和 Java 单击 reCAPTCHA

为什么在尝试让驱动程序单击 reCAPTCHA 按钮时出现错误?

这是我试图让它工作的网站:https : //rsps100.com/vote/760/

到目前为止,这是我当前的代码:

WebElement iframeSwitch = driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div/div/div[2]/div/form/div/div/div/div/iframe"));
driver.switchTo().frame(iframeSwitch);
driver.findElement(By.cssSelector("div[class=recaptcha-checkbox-checkmark]")).click();
Run Code Online (Sandbox Code Playgroud)

iframe selenium recaptcha selenium-webdriver webdriverwait

7
推荐指数
1
解决办法
2万
查看次数

Selenium等待用户单击python中的警报对话框

我在浏览器中创建了一个对话框(当用户输入详细信息发生错误时,会发生此对话框)。我需要等到用户单击对话框后再执行自动执行(仅用于测试)。这是我所拥有的

# driver is a chrome web driver
driver.execute_script("alert('qwer');")
wait = WebDriverWait(driver, 10)    
element = wait.until(EC.alert_is_present()) 
Run Code Online (Sandbox Code Playgroud)

我尝试在线搜索,但是只有当用户单击网页内的按钮而不是生成的对话框时,才能得到答案。怎么做(如果可能的话)?

python alert click selenium-webdriver webdriverwait

7
推荐指数
1
解决办法
179
查看次数

使用 Selenium 和 Python 查找存在 data-tb-test-id 属性而不是 id 的元素

我正在尝试使用 Selenium 查找元素,但没有找到。请遵循 HTML 代码:

\n\n
<div aria-disabled="false"\n     data-tb-test-id="DownloadCrosstab-Button"\n     role="button"\n     tabindex="0"\n     style="font-size: 12px; font-weight: normal; color: rgba(0, 0, 0, 0.7); display: inline-block; padding: 0px 24px; position: relative; text-align: center; border-style: solid; border-width: 1px; border-radius: 1px; height: 24px; line-height: 22px; min-width: 90px; box-sizing: border-box; outline: none; white-space: nowrap; user-select: none; cursor: default; background-color: rgba(0, 0, 0, 0); border-color: rgb(203, 203, 203); margin-top: 8px; width: 100%; -webkit-tap-highlight-color: transparent;"\n>Tabela de refer\xc3\xaancia cruzada</div>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我已经尝试过以下代码:

\n\n
x = browser.find_element_by_id("Downloadcrosstab")\nx = browser.find_element_by_link_text("Downloadcrosstab-Button")\nx = browser.find_element_by_class_name(\'Crosstab\')\n
Run Code Online (Sandbox Code Playgroud)\n\n …

python selenium xpath css-selectors webdriverwait

7
推荐指数
2
解决办法
4万
查看次数

ElementClickInterceptedException:消息:元素点击被拦截:元素 &lt;label&gt; 不能用 Selenium 和 Python 点击

我试图单击“所有主题”和“所有状态”复选框,然后搜索结果。当我运行脚本时,会打开一个 1036x674 大小的 chrome 窗口。

如果我不理会窗口,我会收到元素点击拦截错误。如果我最小化或最大化窗口,我的脚本工作正常。

我正在使用 Selenium 3.141.0、chrome 76、chromedriver 76 和 python 3.6

chromedriver_path = r"C:\Users\path\to\chromedriver.exe"
browser = webdriver.Chrome(executable_path=chromedriver_path)
url = "http://www.ncsl.org/research/transportation/autonomous-vehicles-legislative-database.aspx"

topics_xpath = "//*[@id=\"dnn_ctr81355_StateNetDB_UpdatePanel1\"]/div[1]/div[2]/span/label"
states_xpath = "//*[@id=\"dnn_ctr81355_StateNetDB_UpdatePanel1\"]/div[2]/div[2]/span/label"
browser.get(url)
time.sleep(30)

elem = browser.find_element_by_xpath(topics_xpath)
elem.click()
time.sleep(5)
elem = browser.find_element_by_xpath(states_xpath)
elem.click()
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:

ElementClickInterceptedException:消息:元素点击被拦截:
元素 <label for="dnn_ctr81355_StateNetDB_ckBxAllTopics">...</label> 在点 (259, 665) 处不可点击。
其他元素将收到点击:
<label for="dnn_ctr81355_StateNetDB_ckBxTopics_0">...</label>
(会话信息:chrome=76.0.3809.100)

将被单击的复选框位于我要单击的复选框的正下方。

python selenium xpath css-selectors webdriverwait

7
推荐指数
1
解决办法
2万
查看次数

WebDriver等待多个条件(OR逻辑评估)

使用 python,WebDriverWait 方法用于等待网页上出现 1 个元素。不用多次try/except,如何使用这个方法呢?对于使用此方法的多种情况,是否有 OR 选项? https://selenium-python.readthedocs.io/waits.html

python selenium webdriver selenium-webdriver webdriverwait

7
推荐指数
1
解决办法
5518
查看次数

如何从推特上抓取所有主题

推特中的所有主题都可以在这个链接中找到 我想用里面的每个子类别抓取。

BeautifulSoup 在这里似乎没有用。我尝试使用 selenium,但我不知道如何匹配单击主类别后出现的 Xpath。

from selenium import webdriver
from selenium.common import exceptions

url = 'https://twitter.com/i/flow/topics_selector'
driver = webdriver.Chrome('absolute path to chromedriver')
driver.get(url)
driver.maximize_window()

main_topics = driver.find_elements_by_xpath('/html/body/div[1]/div/div/div[1]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div/div/div/div/span')

topics = {}
for main_topic in main_topics[2:]:
    print(main_topic.text.strip())
    topics[main_topic.text.strip()] = {}
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用 来单击主类别main_topics[3].click(),但我不知道如何递归单击它们,直到我只找到Follow右侧的那些。

python selenium xpath web-scraping webdriverwait

7
推荐指数
1
解决办法
372
查看次数

Can I reuse WebDriverWait in multiple sequential waits?

Given I need wait for one textbox appears, do something, and later I will need wait another Textbox. I want to know if this code is correct:

var waitForTextBox = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
waitForTextBox.Until(ExpectedConditions.ElementIsVisible(By.Id("txtFirstName"))).SendKeys("John");
waitForTextBox.Until(ExpectedConditions.ElementIsVisible(By.Id("txtLastName"))).SendKeys("Skeet");
Run Code Online (Sandbox Code Playgroud)

or if instead of reusing waitForTextBox, I will need do like this:

var waitForFirstName = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
waitForFirstName.Until(ExpectedConditions.ElementIsVisible(By.Id("txtFirstName"))).SendKeys("John");

var waitForLastName = new WebDriverWait(driver, TimeSpan.FromSeconds(30));              
waitForLastName.Until(ExpectedConditions.ElementIsVisible(By.Id("txtLastName"))).SendKeys("Skeet");
Run Code Online (Sandbox Code Playgroud)

c# selenium selenium-webdriver webdriverwait

7
推荐指数
1
解决办法
1106
查看次数

通过 Selenium 和 Python 使用带有预期条件的 WebDriverWait 时出现 selenium.common.exceptions.TimeoutException 错误

Traceback (most recent call last):
  File "Inventorytest.py", line 88, in <module>
    j.go_to_application()
  File "Inventorytest.py", line 65, in go_to_application
    EC.element_to_be_clickable((By.ID, 'FavoriteApp_ITEM'))
  File "/home/naroladev/Mercury_Back-End/mercuryenv/lib/python3.6/site-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
Run Code Online (Sandbox Code Playgroud)

我在 EC2 服务器实例上遇到了上述异常。我的脚本在 Ubuntu 和 Mac 操作系统以及本地系统上任何版本的 firefox 和 geckodriver 上都可以正常工作。但是 EC2 ubuntu 18.04.01 版本出现上述错误,在此我也尝试升级和降级 firefox 和 geckodriver 版本,但仍然无法正常工作。谁能帮我提供建议和解决方案。

python selenium timeoutexception webdriverwait expected-condition

6
推荐指数
1
解决办法
2万
查看次数