好,因此,我尝试单击此自动化测试页面(https://www.phptravels.net/)上的下一个按钮。图片: See the button and DOM here.
我尝试通过XPATH定位它:
# first, must set coolbits with nvidia-xconfig
# read more here: https://wiki.archlinux.org/index.php/NVIDIA/Tips_and_tricks
$ nvidia-xconfig --enable-all-gpus
$ nvidia-xconfig --cool-bits=4
$ nvidia-settings -a GPUFanControlState=1
$ nvidia-settings -a GPUTargetFanSpeed=70
# or for a single card:
$ nvidia-settings -a "[gpu:0]/GPUFanControlState=1" -a "[fan:0]/GPUCurrentFanSpeed=70"
和XPATH,但等待它加载:
current_browser.find_element_by_xpath("//th[@class='next']").click()
尽管我付出了很多努力,但始终会抛出WebDriverWait(current_browser, 10).until(EC.presence_of_element_located((By.XPATH, '//th[@class="next"]'))).click()
:
elementNotVisibleException
我应如何定位并单击此按钮?
答案 0 :(得分:0)
您是否尝试过使用Chrome开发工具生成的xpath?它给了我这个xpath:“ / html / body / div [9] / div [2] / table / thead / tr / th [3]”,它似乎正在工作
答案 1 :(得分:0)
这里的问题是,页面内有21个th
类的next
标签。似乎有7个datepicker下拉菜单,每个下拉菜单都包含一个选项,分别用于几天,几个月和几年-您当前的XPath始终会选择它在页面中找到的第一个,这是用于按日期选择签入日期的datepicker (这就是为什么您得到ElementNotVisibleException
的原因。)
在屏幕快照中,您似乎想按月份进行选择,在这种情况下,您的XPath可能如下所示...
签到:
//div[@class='datepicker dropdown-menu'][1]/div[@class='datepicker-months']//th[@class='next']
退房:
//div[@class='datepicker dropdown-menu'][2]/div[@class='datepicker-months']//th[@class='next']
如果希望引用不同的日期选择器,则可以在这些XPath中适当地换出months
,days
和years
-我希望这会有所帮助!