[英]How do I execute a JavaScript code in python using selenium?
I try to extract some info through selenium using these:我尝试使用这些通过硒提取一些信息:
from selenium import webdriver # $ pip install selenium
from selenium.webdriver.chrome.options import Options
path = 'C:/Users/Жираслан/Downloads/chromedriver_win32 (1)/chromedriver.exe'
wd = webdriver.Chrome(executable_path=path)
result = wd.find_element_by_class_name('wrapper__top_3UDaE')
when the code in the web-page's elements are:当网页元素中的代码是:
<div class="wrapper__top_3UDaE">
<h3>Лидерборд</h3>
<span class="wrapper__description_nfMmy">...</span>
</div>
and after之后
result = wd.find_element_by_class_name('wrapper__top_3UDaE')
result
I get the next error:我收到下一个错误:
Message: no such element: Unable to locate element: {"method":"css selector","selector":".wrapper__top_3UDaE"}
(Session info: chrome=86.0.4240.75)
Please, give me a hint on how to implement this correctly.请给我一个关于如何正确实现它的提示。 Thanks.
谢谢。
In your example, you give us the HTML
code for a div
在您的示例中,您为我们提供了
div
的HTML
代码
<div class="wrapper__top_3UDaE">
<h3>Лидерборд</h3>
<span class="wrapper__description_nfMmy">...</span>
</div>
To get your element, you will need the following imports要获取您的元素,您将需要以下导入
from selenium import webdriver
from selenium.webdriver.common.by import By
Then, you can use this xpath
然后,您可以使用此
xpath
//div[@class='wrapper__top_3UDaE']
and you should be able to get your element你应该能够得到你的元素
wd = webdriver.Chrome(executable_path=path)
result = wd.find_element(By.XPATH, "//div[@class='wrapper__top_3UDaE']")
If your div
is a button, you can click on your element如果你的
div
是一个按钮,你可以点击你的元素
wd = webdriver.Chrome(executable_path=path)
result = wd.find_element(By.XPATH, "//div[@class='wrapper__top_3UDaE']")
result.click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.