我有两个元素可以等待,我想wait直到它们中的任何一个出现在页面上。
我正在尝试使用xpath定位器。但它不起作用。
By.xpath("//*[(contains(@id,'idNumber1')) or (contains(@id,'idNumber2'))]"));
Run Code Online (Sandbox Code Playgroud)
这是可以实现的吗?
请帮帮我。
我编写了一个脚本,可以在 Instagram 上成功登录。当我应该在家里使用我的帐户时,该网站会显示一个弹出窗口,询问您是否需要通知。此时,我尝试了很多解决方案,但一无所获。我只是想要,当显示弹出窗口时,脚本应该点击“不是现在”。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
ids = []
driver = webdriver.Chrome(executable_path = '/usr/local/bin/chromedriver')
driver.get("https://www.instagram.com/accounts/login/?source=auth_switcher")
usm = driver.find_element_by_name('username').send_keys("**")
pwd = driver.find_element_by_name('password').send_keys("**")
btnLog = driver.find_element_by_tag_name('form').submit()
acpt = driver.find_element_by_xpath("//*[contains(@class, 'aOOlW HoLwm ')]")
Run Code Online (Sandbox Code Playgroud)
在图像中,突出显示了我要单击的按钮行:

我正在尝试使用 Selenium 在 Python 中自动执行 Google Chrome 会话。到现在为止,我一直在使用扩展来获取 xpath,它工作正常。但是现在,我在使用我找到的 xpath 时遇到错误:
NoSuchElementException:消息:没有这样的元素:无法定位元素:{"method":"xpath","selector":"///*[@id="ok"]"}(会话信息:chrome=71.0.3578.98) (驱动程序信息:chromedriver=2.45.615291(ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),平台=Windows NT 6.3.9600 x86_64)
返回错误的行如下所示:
browser.find_element_by_xpath('//*[@id="ok"]').click()
Run Code Online (Sandbox Code Playgroud)
不幸的是,我需要点击的按钮在网页的深处,需要一个特定的插件,这让你很难复制我的程序流程。因此,我上传了网页源代码的图片(蓝线是我要点击的按钮):
您能否提供一些有关如何更正硒选择器的帮助,以便我能够单击该元素?
有一些方法可以等待对象,例如在 selenium python 中可点击的按钮。我使用time.sleep()和/或WebDriverWait...until,它工作正常。
但是,当有数百个对象时,有没有办法全局设置默认时间延迟,而不是在每个对象上实现它?
该click()行动应该有一个有条件的等待时间?
我试图从 URL https://www.dx3canada.com/agenda/speakers 中提取人们的 href 。
我试过:
elems = driver.find_elements_by_css_selector('.display-flex card vancouver')
href_output = []
for ele in elems:
href_output.append(ele.get_attribute("href"))
print(href_output)
Run Code Online (Sandbox Code Playgroud)
但是输出列表什么都不返回......
预期的 href 如下图所示,我希望输出为 href 列表:

我真的很感谢你的帮助!
隐式、显式、流利等之间有什么区别?
如果我们在隐式等待中设置 10 秒,并且在 10 秒之前,则在 3 秒内只有元素被定位。
到时候会发生什么?它将等待 10 秒钟或继续进行。
selenium selenium-webdriver webdriverwait fluentwait implicitwait
clear()在这种情况下不起作用。我追加后追加。
searchForMovie.clear()无法运作...我也曾尝试传送
CTRL + 'a',然后传送DELETE。同样,我得到的只是附件...
for movie in allMissing:
time.sleep (10)
searchForMovie = WebDriverWait (driver, 10).until \
(EC.presence_of_element_located ((By.CSS_SELECTOR, "#search-text")))
searchForMovie.send_keys (movie)
# click
enter = WebDriverWait (driver, 10).until \
(EC.presence_of_element_located ((By.CSS_SELECTOR, "#search-submit")))
driver.execute_script ("arguments[0].click()", enter)
# clear the search text box
searchForMovie = WebDriverWait (driver, 10).until \
(EC.presence_of_element_located ((By.CSS_SELECTOR, "#search-text")))
searchForMovie.clear()
Run Code Online (Sandbox Code Playgroud) selenium css-selectors python-3.x selenium-webdriver webdriverwait
我正在尝试通过硒在angular7应用程序中阅读文本工具提示。但是获取文本返回空白,而javascript执行程序返回null。

但是获取文本返回空白,而javascript执行程序返回null。
这是空白
driver().get("https://vmware.github.io/clarity/documentation/v0.12/tooltips");
Wait(3000);
System.out.println(driver().findElement(By.xpath("(//span[@class='tooltip-content'])[2]")).getText());
Run Code Online (Sandbox Code Playgroud)
这将返回null
System.out.println(driver().findElement(By.xpath("(//span[@class='tooltip-content'])[2]")).getAttribute("value"));
String theTextIWant = ((JavascriptExecutor) driver()).executeScript("return arguments[0].innerHTML;",driver().findElement(By.xpath("(//span[@class='tooltip-content'])[2]")));
Run Code Online (Sandbox Code Playgroud) https://www.n11.com/telefon-ve-aksesuarlari/cep-telefonu-aksesuarlari
在此网站上,我试图单击(下一页按钮)
我想抓住这条线
<a href="https://www.n11.com/telefon-ve-aksesuarlari/cep-telefonu-aksesuarlari?pg=3" class="next navigation"></a>
Run Code Online (Sandbox Code Playgroud)
我在程序中编写此代码
data=driver.find_elements_by_class_name("next navigation")
Run Code Online (Sandbox Code Playgroud)
我的问题是关于这个问题。
我想提取我尝试过的所有<li>元素文本<ul>
elem = driver.find_elements_by_xpath(("//div[@class='left width50']/p/b/ul"))
len(elem)
Run Code Online (Sandbox Code Playgroud)
给出 '0' 或空列表。
这是 html 源代码
<div class="left width50">
<p><b>Features:</b></p>
<ul>
<li>Easy spray application</li>
<li>Excellent bonding properties</li>
<li>Single package</li>
<li>Mixed with clean potable water at job site</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
这里是网站的链接
有什么建议怎么办?
我看到了类似的问题,但就我而言,我的代码中甚至没有“init”函数。如何解决这个问题呢?问题出在线路上(EC.element_to_bo_clickable)
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="C:\Chromedriver\chromedriver.exe")
driver.implicitly_wait(1)
driver.get("https://cct-103.firebaseapp.com/")
element = WebDriverWait(driver, 1).until
(EC.element_to_be_clickable(By.CLASS_NAME, "MuiButton-label"))
element.click()
Run Code Online (Sandbox Code Playgroud) webdriverwait ×11
selenium ×10
python ×5
xpath ×4
python-3.x ×3
angular ×1
angular7 ×1
fluentwait ×1
iframe ×1
implicitwait ×1
instagram ×1
java ×1
webdriver ×1