简体   繁体   English

如何点击本页python中selenium的元素?

[英]How to click on element with selenium in python on this page?

1个

https://iphone.facebook.com/marketplace/selling/item/ https://iphone.facebook.com/marketplace/selling/item/

base on image that i've upload, i have to fill some column and click few button to post product.根据我上传的图片,我必须填写一些列并点击几个按钮来发布产品。 i still try to create selenium bot automation to do it but i have problem on clicking the button element like, post button, category (not button but i have to click it to show its option) and last one is location (not button to but have to click it to show the column).我仍然尝试创建 selenium 机器人自动化来执行此操作,但我在单击按钮元素时遇到问题,例如发布按钮、类别(不是按钮,但我必须单击它以显示其选项),最后一个是位置(不是按钮,而是必须单击它才能显示该列)。

i have csv file as source of data, and i write code below to fill data;我有 csv 文件作为数据源,我在下面编写代码来填充数据;

        scraper.element_send_keys('input[name="title"]', data['Title'])
    scraper.element_send_keys('input[name="price"]', data['Price'])
    scraper.element_send_keys('textarea[name="description"]', data['Description'])

what i need now is click on post button and fill the location and category with data from csv file.我现在需要的是单击发布按钮并使用 csv 文件中的数据填写位置和类别。

sorry for my bad english but i need help.抱歉我的英语不好,但我需要帮助。

Thank you.谢谢你。

I have try using xpath, id and name tag to locate the element for click but not work.我尝试使用 xpath、id 和名称标签来定位要单击的元素,但不起作用。

i want code that can click on button and column that i mention above.我想要可以点击我上面提到的按钮和列的代码。

I think, you should use.keys to click on the post button, and using the id is a good idea.我认为,您应该使用 .keys 来点击发布按钮,使用 id 是个好主意。

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

driver.impicitly_wait(4) 
post_button = driver.find_element(By.ID, 'u_0_25_2e')
post_button.send_keys(Keys.'RETURN')

or 
post_button = driver.find_element(By.ID, 'u_0_27_ty')
post_button.send_keys(Keys.'RETURN')

you can open try, except block or use driver.wait until expected conditions.您可以打开 try, except block 或使用 driver.wait 直到预期的条件。

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM